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條經驗 獲得超6個贊
您可以根據需要使用它,但這里有一個示例:
message.channel.send("React test!").then(messageReaction => {
messageReaction.react("?");
messageReaction.react("?");
});
添加回答
舉報
