我正在制作一个机器人,允许用户挑战别人进行决斗。目前我仍然坚持让僵尸程序只显示已经被接受的决斗,如果它来自受到挑战的用户。原样,它只允许来自原始邮件发件人的响应。任何帮助将不胜感激。
if(command === `${prefix}fight`) {
//checks if the username to fight is in the message
let author1 = message.author.username;
let user = message.mentions.users.first();
if(!user) return message.reply("you did not specify who you would like to fight!");
//checks if the users is trying to fight themselves
if(user.id == message.author.id) return message.reply('you cannot fight yourself!');
//checks if the user is trying to fight the bot
if(user.bot == true)
return message.reply('you cannot fight a bot!');
//saves the two user ids to variables
var fighter1 = message.author.id;
var fighter2 = user.id;
//announces challenge and awaits response
var challenged = user.toString();
message.channel.send(`${challenged}, ${author1} has challenged you to a duel. Do you accept the challenge, yes or no?`)
.then(() => {
message.channel.awaitMessages(response => response.content == 'yes' && message.author.id == fighter2 || response.content == 'no' && message.author.id == fighter2, {
max: 1,
time: 60000,
errors: ['time'],
})
.then((collected) => {
if (collected.first().content == 'yes') {
message.channel.send(`${challenged} has accepted the challenge!`);
}
else if(collected.first().content == 'no') {
message.channel.send(`nope`);
}
})
.catch(() => {
message.channel.send(`No response. Fight has been cancelled.`);
});
});
}
答案 0 :(得分:0)
那是因为您使用的是message.author
而不是response.author
message.channel.awaitMessages(response => return (response.content == 'yes' && message.author.id == fighter2)
|| (response.content == 'no' && message.author.id == fighter2),
{
max: 1,
time: 60000,
errors: ['time'],
})
答案 1 :(得分:0)
看起来您的过滤器功能仅在查看response
时查看content
消息,但是当您重新检查.author.id
时,您会从原始message
获取该消息{1}}开始了战斗(来自挑战者,而不是受到挑战的人)。
尝试更改过滤功能,使用response.author.id
代替message.author.id
,如下所示:
message.channel.awaitMessages(response => response.content == 'yes' && response.author.id == fighter2 || response.content == 'no' && response.author.id == fighter2, {
...
})