2 回答
TA贡献1900条经验 获得超5个赞
从 Discord.js v12 开始,您可以在机器人上启用部分功能,允许其发送未获取消息的事件,但代价是您必须在处理程序开始时自己获取消息:
const Discord = require('discord.js');
// Make sure you instantiate the client with the correct settings
const client = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });
client.on('messageReactionAdd', async (reaction, user) => {
// When we receive a reaction we check if the reaction is partial or not
if (reaction.partial) {
// If the message this reaction belongs to was removed the fetching might result in an API error, which we need to handle
try {
await reaction.fetch();
} catch (error) {
console.error('Something went wrong when fetching the message: ', error);
// Return as `reaction.message.author` may be undefined/null
return;
}
}
// Now the message has been cached and is fully available
console.log(`${reaction.message.author}'s message "${reaction.message.content}" gained a reaction!`);
// The reaction is now also fully available and the properties will be reflected accurately:
console.log(`${reaction.count} user(s) have given the same reaction to this message!`);
});
TA贡献1993条经验 获得超5个赞
您可以根据需要使用它,但这里有一个示例:
message.channel.send("React test!").then(messageReaction => {
messageReaction.react("✅");
messageReaction.react("⛔");
});
添加回答
举报