javascript - 如何使reactionCollector 对remove 事件起作用?
问题描述
所以,我正在开发一个不和谐的机器人。在这里我开始一个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 事件永远不会被调用。有谁知道为什么会这样?我在哪里做错了?
解决方案
要使您的ReactionCollector触发dispose
和remove
事件,您必须在您的ReactionCollectordispose
的CollectorOptions中启用,就像这样:
collector = message.createReactionCollector(filter, { dispose: true });
此外,在操作 ID(雪花)时要小心,它们始终是字符串类型。在您的代码中,您尝试查看是否user.id
不等于一个数字(顺便说一下,这个数字真的很大!)所以不要忘记用引号将 ID 括起来。
return reaction.emoji.name === '⚔' && user.id != "705462496646922311";
推荐阅读
- java - Java 11 连接重置(间歇性)
- python - 使用 OAuth 和 exchangelib 的身份验证错误
- ruby-on-rails - Rails:保存前未使用 assign_attributes 保存数据
- python - 使用 Python 读取 Excel 动态文件引用
- mysql - 如何在dockerfile中恢复mysql db
- php - 如何使用 PayPal Payouts PHP 进行支付
- ajax - Ajax post 适用于空的 ASP.net Web 应用程序,但如果将相同的代码用于 Web Forms 项目,则会导致 401 错误
- javascript - 在 javascript/nodejs 中使用 token 顺序调用 API
- youtrack - 带有冲刺名称的蓝色徽章
- javascript - 如果我们有极长的水平滚动页面,如何在最后一个元素的末尾添加边距/填充,即空间?