为了账号安全,请及时绑定邮箱和手机立即绑定

Discord.JS 反应

Discord.JS 反应

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

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!`);

});


查看完整回答
反对 回复 2023-07-06
?
ibeautiful

TA贡献1993条经验 获得超5个赞

您可以根据需要使用它,但这里有一个示例:


message.channel.send("React test!").then(messageReaction => {

    messageReaction.react("✅");

    messageReaction.react("⛔");

  });


查看完整回答
反对 回复 2023-07-06
  • 2 回答
  • 0 关注
  • 78 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信