2 回答

TA貢獻(xiàn)1900條經(jīng)驗(yàn) 獲得超5個(gè)贊
從 Discord.js v12 開(kāi)始,您可以在機(jī)器人上啟用部分功能,允許其發(fā)送未獲取消息的事件,但代價(jià)是您必須在處理程序開(kāi)始時(shí)自己獲取消息:
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貢獻(xiàn)1993條經(jīng)驗(yàn) 獲得超6個(gè)贊
您可以根據(jù)需要使用它,但這里有一個(gè)示例:
message.channel.send("React test!").then(messageReaction => {
messageReaction.react("?");
messageReaction.react("?");
});
添加回答
舉報(bào)