問題描述
所以,我正在開發(fā)一個不和諧的機器人.這里我開始一個reactionCollector
.當(dāng)一個反應(yīng)被收集時,它會做一些事情,當(dāng)反應(yīng)被移除時,它應(yīng)該做其他事情.
So, I am working on a discord bot. Here I start a reactionCollector
. When a reaction is collected, it does something, and when the reaction is removed, it should do something else.
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')
});
永遠(yuǎn)不會調(diào)用 remove 事件.有誰知道為什么會這樣?我哪里做錯了?
The remove event never gets called. Does anyone know why this happen? Where did I do a mistake?
推薦答案
讓你的 ReactionCollector 觸發(fā) dispose
和 remove
事件,您必須在 dispose/discord.js.org/#/docs/main/stable/typedef/CollectorOptions" rel="nofollow noreferrer">CollectorOptions 你的 ReactionCollector 就像這樣:
To make your ReactionCollector fire dispose
and remove
events you have to enable dispose
in the CollectorOptions of your ReactionCollector just like that :
collector = message.createReactionCollector(filter, { dispose: true });
另外,在操作 ID 時要小心(Snowflakes),它們總是字符串類型.在您的代碼中,您嘗試查看 user.id
是否不等于一個數(shù)字(順便說一下,這個數(shù)字真的很大!)所以不要忘記用引號將 ID 括起來.
Also, be carefull when manipulating IDs (Snowflakes), they are always type of String. In your code you try to see if user.id
is not equal to a number (really big number by the way!) so don't forget to surround IDs with quotes.
return reaction.emoji.name === '?' && user.id != "705462496646922311";
這篇關(guān)于如何使reactionCollector 對remove 事件起作用?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!