How can I make a reactionCollector on a remove event work?(如何使reactionCollector 对remove 事件起作用?)
问题描述
所以,我正在开发一个不和谐的机器人.这里我开始一个reactionCollector.当一个反应被收集时,它会做一些事情,当反应被移除时,它应该做其他事情.
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')
});
永远不会调用 remove 事件.有谁知道为什么会这样?我哪里做错了?
The remove event never gets called. Does anyone know why this happen? Where did I do a mistake?
推荐答案
让你的 ReactionCollector 触发 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
是否不等于一个数字(顺便说一下,这个数字真的很大!)所以不要忘记用引号将 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";
这篇关于如何使reactionCollector 对remove 事件起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使reactionCollector 对remove 事件起作用?


基础教程推荐
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01