简体   繁体   English

Discord.JS V13 client.on messagecreate 未触发

[英]Discord.JS V13 client.on messagecreate not firing

I've just recently finished upgrading my Discord.js bot to v13 and now the client.on(messageCreate) function doesn't fire?我最近刚刚将我的 Discord.js bot 升级到 v13,现在 client.on(messageCreate) 函数没有触发? None of my code in it ever runs and I'm really confused as to why.我的代码都没有运行过,我真的很困惑为什么。

Before anybody asks, I have already set my intents.在任何人问之前,我已经设定了我的意图。

const client = new Discord.Client({
  intents: [ Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.DIRECT_MESSAGES ],
  partials: ['MESSAGE', 'CHANNEL', 'REACTION'], 
});

I have two functions, the client.on fires but the message doesn't我有两个功能,client.on 触发但消息没有

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on('messageCreate', msg => {
  console.log(anything)
}

You could try replacing your messageCreate with async option, probs don't fix your issue but you can always try您可以尝试用 async 选项替换您的messageCreate ,问题不能解决您的问题,但您可以随时尝试

client.on('messageCreate', async (message) => {
      console.log("DEBUG");
}

See if there is any errors on your console or does it send "DEBUG" message when you sent message to channel that the bot can see .查看您的控制台上是否有任何错误,或者当您向机器人可以看到的频道发送消息时,它是否发送“DEBUG”消息。

On my own bot I do not have partials set, so you probably don't need them either.在我自己的机器人上,我没有设置部分,所以你可能也不需要它们。

Make sure you have also included your discord.js properly, here is example:确保您还正确包含了您的 discord.js,这是示例:

const { Client, Intents } = require("discord.js");

Make sure you include GUILDS in your list of intents.确保在意图列表中包含GUILDS Otherwise, the bot can only see messages that have been sent after the bot itself sent a message.否则,bot 只能看到 bot 本身发送消息后已发送的消息。

In my case, I needed to set these:就我而言,我需要设置这些:

partials: ['MESSAGE', 'CHANNEL', 'REACTION']
intents: ['DIRECT_MESSAGES', 'DIRECT_MESSAGE_REACTIONS', 'GUILD_MESSAGES', 'GUILD_MESSAGE_REACTIONS', 'GUILDS']

but the particulars will vary by your use case.但具体情况会因您的用例而异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM