首页 > 解决方案 > 当发出命令的用户对以下选项之一做出反应时,如何让机器人编辑自己发送的消息?

问题描述

所以我正在开发一个创建频道的功能,将其放入一个类别,向该频道发送消息。所有这些目前都在工作,但是,我正在寻找一种方法让机器人通过使用 discordjs 的 awaitReactions 功能来听取对该消息的反应。

我目前在哪里:我已经对此事进行了一些研究,但我似乎无法弄清楚。我已经让机器人对自己的消息做出反应,但我希望它听取发出命令的用户是否对下面提供的反应之一做出反应。当发出命令的用户对消息做出反应时,我希望机器人发送的消息进行编辑并说其他内容。

    let name =  message.author.username;
    let channel = message.guild.createChannel(name, {
            type: "text",
            permissionOverwrites: [{
                id: message.author,
                deny: ["MANAGE_MESSAGES"],
                allow: ["SEND_MESSAGES", "VIEW_CHANNEL"]
            },
            {
                id: "466764415476432920",
                deny: ["SEND_MESSAGES", "VIEW_CHANNEL"]
            },
            {
                id: "642073025046642708",
                allow: ["VIEW_CHANNEL", "SEND_MESSAGES"]
            },
            {
                id: "569736927427821569",
                allow: ["VIEW_CHANNEL", "SEND_MESSAGES"]
            }]

        }).then(channel => {
            let category = message.guild.channels.find(c => c.name == "Support Area" && c.type == "category");
            if (!category) throw new Error("Category channel does not exist");
            channel.setParent(category.id);
            channel.send(`Life Can Be Ruff! - You’re not alone ${message.author} :heart:
Resources and coping skills while I connect you to a <@&569736927427821569>`).then(reactmessage => { 
    reactmessage.react(""),
    reactmessage.react(""),
    reactmessage.react("")


})
          }).catch(console.error);

这就是我目前所在的位置。

标签: javascriptdiscord.js

解决方案


您可以等待来自特定用户的特定反应,如下所示:

const filter = (reaction, user) => {
    return reaction.emoji.name === '' && user.id === message.author.id;
};

message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
   .then(collected => console.log(collected.size))
   .catch(collected => {
   console.log(`Reacted! :D`);
});

这将等待一分钟!


推荐阅读