[英]Why messageReactionAdd do nothing discord.js
I'am trying to code a discord bot with node.js, but i have a problem with messageReactionAdd I don't now why the bot does nothing when i react with an emoji.我正在尝试使用 node.js 编写一个不和谐的机器人,但我对 messageReactionAdd 有问题我现在不明白为什么当我对表情符号做出反应时机器人什么都不做。
My code :我的代码:
bot.on('messageReactionRemove', (reaction, user) => {
console.log("that work 1");
if(reaction.emoji.name === "white_check_mark") {
console.log("that work 2");
}})
Events messageReactionAdd
and messageReactionRemove
working only for cached messages.事件
messageReactionAdd
和messageReactionRemove
仅适用于缓存的消息。 You need add raw event to your code for trigger any message.您需要在代码中添加原始事件以触发任何消息。 https://github.com/AnIdiotsGuide/discordjs-bot-guide/blob/master/coding-guides/raw-events.md
https://github.com/AnIdiotsGuide/discordjs-bot-guide/blob/master/coding-guides/raw-events.md
The message must be cached before it will work.消息必须先缓存,然后才能工作。 Any messages that come in while your bot is open will automatically get cached, but if it's for a specific older message, you can use:
在您的机器人打开时传入的任何消息都将自动被缓存,但如果是针对特定的较旧消息,您可以使用:
client.channels.get(CHANNELID).fetchMessage(MESSAGEID);
to cache it.缓存它。 After doing this (each time your script is run) you will receive reaction events for that message.
执行此操作后(每次运行脚本时),您将收到该消息的反应事件。
你正在做反应删除,你需要使用 Unicode 表情符号 - 你可以在网上找到这些并复制它们
You should listen to the messageReactionAdd
event.您应该收听
messageReactionAdd
事件。
Keep also in mind that ReactionEmoji.name
is the Unicode for that emoji: you can get the Unicode symbol by writing a backslash before the emoji, like \\:joy:
.还要记住,
ReactionEmoji.name
是那个表情符号的 Unicode:你可以通过在表情符号前写一个反斜杠来获得 Unicode 符号,比如\\:joy:
。 The Unicode for :white_check_mark:
is ✅. :white_check_mark:
的 Unicode 是 ✅。
This should be your code:这应该是你的代码:
bot.on('messageReactionAdd', (reaction, user) => {
console.log("first check");
if (reaction.emoji.name === "✅") {
console.log("second check");
}
});
This will work on every cached message, if you want it to work only on a specific message, try using Message.awaitReactions()
or Message.createReactionCollector()
这将适用于每个缓存的消息,如果您希望它仅适用于特定的消息,请尝试使用
Message.awaitReactions()
或Message.createReactionCollector()
Update 2022. You may need to add intents for GUILD_MESSAGES
and GUILD_MESSAGE_REACTIONS
with cache messages to make it work. 2022 年更新。您可能需要使用缓存消息为
GUILD_MESSAGES
和GUILD_MESSAGE_REACTIONS
添加意图以使其工作。
Reference: https://discordjs.guide/popular-topics/reactions.html#listening-for-reactions-on-old-messages参考: https : //discordjs.guide/popular-topics/reactions.html#listening-for-reactions-on-old-messages
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS],
partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.