Javascript 如何使remove事件上的reactionCollector工作?
所以,我正在开发一个discord机器人。在这里,我启动了一个Javascript 如何使remove事件上的reactionCollector工作?,javascript,bots,discord.js,Javascript,Bots,Discord.js,所以,我正在开发一个discord机器人。在这里,我启动了一个reactionCollector。当一个反应被收集时,它会做一些事情,当反应被移除时,它应该做一些其他的事情 await message.channel.send(embed) then(async function (message) { await message.react('⚔') const filter = (reaction, user) => { return reaction
reactionCollector
。当一个反应被收集时,它会做一些事情,当反应被移除时,它应该做一些其他的事情
await message.channel.send(embed)
then(async function (message) {
await message.react('⚔')
const filter = (reaction, user) => {
return reaction.emoji.name === '⚔' && user.id != 705462496646922311
};
collector = message.createReactionCollector(filter);
collector.on('collect', async (reaction, user) => {
// Do something.
});
collector.on('remove', (reaction, user) => {
// Do something.
});
})
.catch(function() {
message.channel.send('Error while adding the reaction. Try again')
});
永远不会调用remove事件。有人知道为什么会这样吗?我在哪里犯了错误?要使您的火灾dispose
和remove
事件,您必须在您的系统中启用dispose
,如下所示:
collector=message.createReactionCollector(过滤器,{dispose:true});
另外,在操作IDs()时要小心,它们总是字符串类型。在您的代码中,您试图查看user.id
是否不等于一个数字(顺便说一句,这个数字真的很大!),所以不要忘记用引号括住id
return reaction.emoji.name=='⚔' && user.id!="705462496646922311";
我很确定在第二行,应该是.then()
而不是then()
这是一个复制粘贴错误!我很抱歉。