【问题标题】:discord.js Bot didn't see message before restartdiscord.js Bot 重启前没有看到消息
【发布时间】:2021-02-10 01:46:51
【问题描述】:

抱歉我的英语不好。

我想让角色反应机器人我的问题是我的机器人在重启之前看不到消息发送

我收到了这个代码,但他没有看到对旧消息的反应。

我该怎么做才能让这段代码看到对旧消息的反应。

const Discord = require('discord.js');
const client = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });

client.once('ready', () => {
    console.log('Ready!');
});

client.on('messageReactionAdd', async (reaction, user) => {
    if (reaction.message.partial) {
        try {
            await reaction.message.fetch();
        }
        catch (error) {
            console.error('Something went wrong when fetching the message: ', error);
        }
    }
    console.log(`${user.username} reacted with "${reaction.emoji.name}".`);
});

client.on('messageReactionRemove', async (reaction, user) => {
    if (reaction.message.partial) {
        try {
            await reaction.message.fetch();
        }
        catch (error) {
            console.error('Something went wrong when fetching the message: ', error);
        }
    }
    console.log(`${user.username} removed their "${reaction.emoji.name}" reaction.`);
});

client.login('my token');

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:

    除了检查反应消息是否部分,还要检查反应本身。

    if (reaction.partial) {
     try {
      await reaction.fetch();
     } catch (error) {
      console.error('Something went wrong when fetching the reaction: ', error);
     }
    }
    

    【讨论】:

    • 感谢您的回答。那是行不通的,我还需要在机器人开启时发送消息并对他做出反应,以查看对旧消息的反应。
    • 对不起,我没听懂。
    猜你喜欢
    • 2019-11-17
    • 2020-06-13
    • 1970-01-01
    • 2022-10-01
    • 2021-12-13
    • 2023-04-10
    • 2021-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多