【问题标题】:I'm trying to send a message after 2 persons react to a discord message using my discord bot我正在尝试在 2 个人使用我的不和谐机器人对不和谐消息做出反应后发送消息
【发布时间】:2020-11-20 15:27:19
【问题描述】:

我正在为我的 Discord 机器人制定战斗命令,人们可以在其中互相战斗。
这是我当前的代码:

//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 文本会显示出来。
如果您发现我的错误,请告诉我!

【问题讨论】:

  • 我认为您的错误与过滤器有关,您只检查发送战斗请求的人的拇指,但从不检查opponent的ID

标签: javascript node.js discord discord.js


【解决方案1】:

正如@Sean 在 cmets 中所说,您的 filter 配置错误。

你只允许命令的作者反应通过你的收集器,所以你应该用这个替换你的过滤器:

const filter = (reaction, user) => { return reaction.emoji.name === '?' && !user.bot; };

这将允许除机器人以外的任何人玩游戏!
我希望这能解决您的问题!

PS:您还应该将收集器的max 降低到 2 ;)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-10
    • 1970-01-01
    • 2022-11-02
    • 2018-11-19
    • 2021-04-03
    • 2020-09-03
    • 2020-05-11
    • 2020-12-06
    相关资源
    最近更新 更多