Discord.js 不发送消息也不报错

Discord.js not sending message nor giving an error

我的 discord.js 版本是 v13,它没有发送消息,也没有在控制台中给出错误,所以我可以尝试找出问题所在。

代码本身超过4000行代码,所以我试着把它放在一个单独的脚本中只测试一个功能(即ping功能),但仍然没有。

如果你问,这个 async 只是主脚本中我经常使用 await 的另一个函数的一部分。

const Discord = require('discord.js');
const client = new Discord.Client({ intents: [ 'DIRECT_MESSAGES', 'GUILD_MESSAGES' ] });
const config = require("./config.json");

client.on("ready", () => {
  console.log(`Main script ready! Currently in ${client.guilds.size} servers!`);
  client.user.setActivity("Using a test script");

});

client.on('messageCreate', async message => {
  if(message.author.bot) return;
  if(message.content.indexOf(config.prefix) !== 0) return;
  const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
  const command = args.shift().toLowerCase()
  if (message.channel.type == "dm") return;

  if(command === "ping") {
    const m = await message.channel.send("Loading...")
    m.edit(`Pong! ${m.createdTimestamp - message.createdTimestamp}ms. API ${Math.round(client.ping)}ms`)
  }
});

client.login(config.token);

你不见了Intents.FLAGS.GUILDS.

变化:

const client = new Discord.Client({ intents: [ 'DIRECT_MESSAGES', 'GUILD_MESSAGES' ] });

const client = new Discord.Client({ intents: [ 'GUILDS', 'DIRECT_MESSAGES', 'GUILD_MESSAGES' ] });