Discord.JS 反应

我正在开发一个票证机器人,我希望它能够让您对消息做出反应以创建票证。我可以发送消息,但当我使用时,bot.on('messageReactionAdd')如果我的机器人重新启动,它不会检测到已添加反应,除非您发送新消息并对自机器人上线以来创建的消息做出反应。这对我来说是一个问题,我知道它是可以解决的。我尝试过谷歌搜索,但无法解决问题。这里有人可以帮助我吗?



慕姐4208626
浏览 106回答 2
2回答

梵蒂冈之花

从 Discord.js v12 开始,您可以在机器人上启用部分功能,允许其发送未获取消息的事件,但代价是您必须在处理程序开始时自己获取消息:const Discord = require('discord.js');// Make sure you instantiate the client with the correct settingsconst 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!`);});

ibeautiful

您可以根据需要使用它,但这里有一个示例:message.channel.send("React test!").then(messageReaction => {    messageReaction.react("✅");    messageReaction.react("⛔");  });
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript