简体   繁体   English

Discord.js messageReactionAdd 未触发

[英]Discord.js messageReactionAdd Not firing

I understand that messageReactionAdd only works with cached messages but even after manually caching them it still wont fire.我知道 messageReactionAdd 仅适用于缓存的消息,但即使在手动缓存它们之后它仍然不会触发。

Currently my code is:目前我的代码是:

client.once('ready', () => { 
    console.log(config.readymesssage); 
    var channel = client.channels.resolve('761577724379791450');
    channel.messages.fetch({limit: 90}).then((message) => {
        console.log("done")
    })
});

client.on('messageReactionAdd', async(reaction) => {
    console.log("reacted");
});

I have tried using raw events I used the code block from Here and I have also tried using partials, neither of which seem to be working.我尝试过使用原始事件,我使用了Here 中的代码块,我也尝试过使用部分事件,但它们似乎都不起作用。 I'm unsure as to what else I cant try.我不确定还有什么我不能尝试。

Enabling intents has fixed the issue, they first needed turning on in the developer portal and then I needed to add the following lines,启用意图已经解决了这个问题,他们首先需要在开发者门户中打开,然后我需要添加以下几行,

let Intss = new Discord.Intents(Discord.Intents.ALL);

const client = new Discord.Client({ws: { intents: Intss }});

Now the event is firing as expected.现在事件按预期触发。

Another working solution that is most likely better is另一个最有可能更好的工作解决方案是

const bot = new Discord.Client({ partials: ['USER', 'REACTION', 'MESSAGE'] });

Now, you will have to check for partials before doing anything with the data (and fetch the data if it is partial).现在,您必须在对数据执行任何操作之前检查部分数据(如果数据是部分数据,则获取数据)。 But this way, you won't have to deal with intents and if your bot scales to 100+ servers, you won't have to wait for verification either.但是这样,您就不必处理意图,如果您的机器人扩展到 100 多个服务器,您也不必等待验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM