我正在为我的不和谐机器人发出战斗命令,人们可以互相战斗。
这是我当前的代码:
//rng battl command (my whole life has lead up to this and bela cant stop me)
if(message.content.startsWith(`k!battle`)) {
var opponent = message.content.split(' ').slice(1).join(' ')
if(!opponent) return message.reply('Wait, who were you going to battle again?\nProper command useage: **k!battle <@username>**')
message.channel.send('Mentioned user, you have been challenged to a battle! Do you accept?')
message.channel.send(opponent)
//battle accept/deny
message.react('?').then(() => message.react('?'));
const filter = (reaction, user) => {
return reaction.emoji.name === '?' && user.id === message.author.id;
};
message.awaitReactions(filter, { max: 3, time: 30000, errors: ['time'] })
.then(collected => message.channel.send('Let the battle commence! :KirbyPopcorn:'))
.catch(collected => {
message.channel.send(`Battle Expired.`);
});
}
只要两个用户对消息做出反应,都不会发生任何事情,但是30秒后,将显示“ Battle Expired”文本。
如果您发现我的错误,请告诉我!
答案 0 :(得分:1)
正如@Sean在评论中所说,您的filter
配置错误。
您只允许命令的作者反应通过收集器,因此您应使用以下过滤器替换过滤器:
const filter = (reaction, user) => { return reaction.emoji.name === '?' && !user.bot; };
该程序将允许除机器人以外的任何人玩游戏!
希望这可以解决您的问题!
PS:您还应该将收集器的max
降低到2;)