简体   繁体   English

反应后 Discord.js 编辑消息

[英]Discord.js edit message after a reaction

I've just started with javascript trying to set up an discord bot with discord.js.我刚刚开始使用 javascript 尝试使用 discord.js 设置一个不和谐的机器人。 I want to use this bot as an 'easy' way to organize raids.我想使用这个机器人作为组织突袭的“简单”方式。 So people only need to klick on the Icon to sign in for the raid.所以人们只需要点击图标来登录突袭。

const Discord = require('discord.js');
const bot = new Discord.Client();

... token, prefix etc. ...令牌,前缀等。

bot.on('message', message => {
    if (message.content.startsWith(PREFIX)) {
        let args = message.content.substring(PREFIX.length).split(" ");

... some stuff for checking the command ...一些检查命令的东西

message.channel.send('RaidID: ' + RaidID + '\nRaid: GOS \nRaid Leader: <@' + message.author.id + '> \nDate: ' + args[2] + '\nTime: ' + args[3]).then(messageReaction => {
                                            messageReaction.react('✅');
                                        });

so far the code works fine.到目前为止,代码工作正常。 It checks date and time just fine.它检查日期和时间就好了。 Now I want to detect if someone have reacted to the message and mention him in the message by editing it.现在我想检测是否有人对消息做出了反应,并通过编辑消息在消息中提及他。 And I'm just not getting how to work with awaitReactions .我只是不知道如何使用awaitReactions Or if it even wokrs with awaitReactions .或者,如果它甚至与awaitReactions一起awaitReactions

You can replace your current message funtion您可以替换您当前的消息功能

message.channel.send('RaidID: ' + RaidID + '\nRaid: GOS \nRaid Leader: <@' + message.author.id + '> \nDate: ' + args[2] + '\nTime: ' + args[3]).then(messageReaction => {
                                            messageReaction.react('✅');
                                        });

With this function:有了这个功能:

message.channel
    .send(
        "RaidID: " +
            RaidID +
            "\nRaid: GOS \nRaid Leader: <@" +
            message.author.id +
            "> \nDate: " +
            args[2] +
            "\nTime: " +
            args[3]
    )
    .then((messageReaction) => {
        messageReaction.react("✅");
        messageReaction.awaitReactions((args, user) => {
            return !user.bot && args._emoji.name === "✅";

        }, { max: 1 }).then(reaction => {
            // SOMEONE REACTED
            console.log('REACTION');
        });
    });

It adds the .awaitReactions function in the .then of the promise.它添加了.awaitReactions的功能.then承诺的。 It checks whether the reaction is made by a user and the emoji ✅.它会检查用户和表情符号 ✅ 是否做出了反应。 In case of a correct reaction, the part at // SOMEONE REACTED is being called.如果反应正确,则调用// SOMEONE REACTED的部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM