【问题标题】:Discord.js edit message after a reaction反应后 Discord.js 编辑消息
【发布时间】:2020-06-25 20:39:22
【问题描述】:

我刚开始使用 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 一起工作。

【问题讨论】:

    标签: javascript discord discord.js


    【解决方案1】:

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

    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 的 .then 中添加了 .awaitReactions 函数。它检查用户和表情符号✅是否做出反应。如果反应正确,将调用// SOMEONE REACTED 处的部分。

    【讨论】:

    • 谢谢- 我想我理解它是如何工作的。即使它只能检测 1 个反应,我也可以找到检测所有 5 个我需要检测的反应的解决方案。
    猜你喜欢
    • 2021-05-08
    • 2019-11-17
    • 1970-01-01
    • 2021-03-31
    • 2021-05-13
    • 2021-01-03
    • 2021-03-23
    • 2020-09-08
    • 1970-01-01
    相关资源
    最近更新 更多