如何让机器人发送消息,然后机器人对该消息做出反应,然后检测何时有人对其做出反应?

时间:2020-02-22 23:48:51

标签: javascript discord.js

因此,我正在制作此东西,您可以在其中执行此命令,它会检查您是否购买了东西(将其发送给工作人员)。因此,我的工作量很大,但我仍坚持如何执行类似机器人说“您完成了吗?”的工作。并以❎和to响应该消息。当您按下其中之一时,它就会执行代码。

或者将其设置为仅与with反应,并检测到有人对其做出反应。

目前,我有:

message.channel.send(new Discord.RichEmbed().setTitle("Rank-Up Application:").setDescription(`**If you wish to send an application to get Ranked-Up in the Discord & ROBLOX Group, this is the right place to do it! **`).setFooter("When you have done that, say done.").setColor("#ff4757")).then(() => {
        message.channel.awaitMessages(filter, { maxMatches: 1, time: 90000, errors: ['time']})
        .then(collected => {
          message.channel.send(":grey_exclamation: **Sending...**")
          client.channels.get(`622386044914106388`).send(new Discord.RichEmbed().setTitle("New Rank-Up!").addField(`**The user ${username} has sent in an application to get ranked. Please check the following links to see if you should rank him. Remember: True = Owns Class, False = Doesn't own Class.**`).addField(`Plus: ${plus}`).addField(`Advanced: ${advanced}`).setTimestamp().setFooter("When you have done that, say done.").setColor("#ff4757"))

所以最后一行代码是它应该在下面说出消息的位。我对此非常执着,甚至不知道应该输入什么起始代码。

1 个答案:

答案 0 :(得分:0)

也许您正在寻找类似的东西。我在门票上用它来关闭人们。对我来说很好。

message.channel.send(`Message that will have reactions on it.`).then(msg => {
    msg.react('❌');
    // Wait 300ms to make sure the tick emoji is made after the first reaction. Just incase the API is on the slow side.
    setTimeout(function(){msg.react('✅');},300);

    // Create a filter to collect, making sure it only checks for non bot users.
    // If you want to check for the message author use user.id == message.author.id
    const filterEmojis = (reaction, user) => {
        return ['❌', '✅'].includes(reaction.emoji.name) && user.bot == false;
    };
    // Await for a user to react as per our filter above.
    msg.awaitReactions(filterEmojis, {time: 60000}).then(collected => {
        const reaction = collected.first();
        // Check if the reaxtion is an X.
        if(reaction.emoji.name === '❌') {
            // Do something when this is reacted too.
        }
        // Check if the reaxtion is a tick.
        if(reaction.emoji.name === '✅') {
            // Do something when this is reacted too.
        }
    }).catch(() => {
        // Catch errors.
    });
}).catch(console.error);