【发布时间】:2020-08-21 08:06:26
【问题描述】:
我正在处理 discord.js 中的机器人,目前正在尝试执行以下操作:
通过触发一个名为tournament prepare 的命令,机器人会等待用户输入reactionCollector,收集想要参加比赛的用户的反应。
稍后,当开始比赛的用户使用命令tournament begin 时,机器人应该关闭收集器,并输出一个包含参加比赛的玩家姓名的列表。
这是我尝试过的:
// initialise the collector
var collector = null;
if(message.content.startsWith(`${prefix}prepare`)) {
message.channel.send('A message')
.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', (reaction, user) => {
// code here
});
})
.catch(function() {
message.channel.send('Error while adding the reaction. Try again')
});
}
if(message.content.startsWith(`${prefix}begin`)) {
if(collector == null) {
message.channel.send('Error message');
return;
}
collector.stop();
collector.on('end', collected => {
// code here
});
}
在结束事件之前一切正常。
文档说明了 stop() 方法:Stops this collector and emits the end event.
我确信在使用 stop() 方法后收集器会停止,因为我已经调试过它,但由于某些原因,end 事件永远不会被调用。有什么帮助吗?
【问题讨论】:
标签: events bots discord.js