首页 > 解决方案 > 反应后 Discord.js 编辑消息

问题描述

我刚刚开始使用 javascript 尝试使用 discord.js 设置一个不和谐机器人。我想用这个机器人作为组织突袭的“简单”方式。因此,人们只需点击图标即可登录突袭。

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

...令牌,前缀等

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

...一些检查命令的东西

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

到目前为止,代码工作正常。它检查日期和时间就好了。现在我想检测是否有人对消息做出反应,并通过编辑在消息中提及他。而且我只是不知道如何使用awaitReactions. 或者,如果它甚至可以与awaitReactions.

标签: javascriptdiscorddiscord.js

解决方案


您可以替换您当前的消息功能

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

使用此功能:

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');
        });
    });

它在 promise中添加了.awaitReactions函数。.then它检查用户和表情符号✅是否做出反应。如果反应正确,// SOMEONE REACTED则调用 at 部分。


推荐阅读