如何让bot在反应后将消息发送到另一个频道|不和谐.js

Posted

技术标签:

【中文标题】如何让bot在反应后将消息发送到另一个频道|不和谐.js【英文标题】:How to make bot send message to another channel after reaction | Discord.js 【发布时间】:2020-10-27 05:16:11 【问题描述】:

如何做到这一点,以便当有人对此命令中的第一个表情符号做出反应时,机器人会删除该消息并将其发送到另一个频道?

当前代码:

const Discord = require("discord.js");

module.exports.run = async (bot, message, args) => 
  if (!message.member.hasPermission("MANAGE_MESSAGES"))
    return message.channel.send("You are not allowed to run this command.");
  let botmessage = args.join(" ");
  let pollchannel = bot.channels.cache.get("716348362219323443");
  let avatar = message.author.avatarURL( size: 2048 );

  let helpembed = new Discord.MessageEmbed()
    .setAuthor(message.author.tag, avatar)
    .setColor("#8c52ff")
    .setDescription(botmessage);

  pollchannel.send(helpembed).then(async msg => 
    await msg.react("715383579059945512");
    await msg.react("715383579059683349");
  );
;
module.exports.help = 
  name: "poll"
;

【问题讨论】:

【参考方案1】:

您可以使用awaitReactionscreateReactionCollectormessageReactionAdd 事件,我认为awaitReactions 是这里的最佳选择,因为其他两个用于更全球化的目的,

const emojis = ["715383579059945512", "715383579059683349"];
pollchannel.send(helpembed).then(async msg => 
    
    await msg.react(emojis[0]);
    await msg.react(emojis[1]);

    //generic filter customize to your own wants
    const filter = (reaction, user) => emojis.includes(reaction.emoji.id) && user.id === message.author.id;
    const options =  errors: ["time"], time: 5000, max: 1 ;
    msg.awaitReactions(filter, options)
        .then(collected => 
            const first = collected.first();
            if(emojis.indexOf(first.emoji.id) === 0) 
                msg.delete();
                // certainChannel = <TextChannel>
                certainChannel.send(helpembed);
             else 
                //case you wanted to do something if they reacted with the second one
            
        )
        .catch(err =>  
           //time up, no reactions 
        );
);

【讨论】:

以上是关于如何让bot在反应后将消息发送到另一个频道|不和谐.js的主要内容,如果未能解决你的问题,请参考以下文章

如何让机器人在收到来自某个消息的反应后将消息发送到特定频道

如何将不和谐消息发送到另一个频道? (不和谐 JS)

试图让不和谐机器人对某个频道内的所有消息做出反应

Bot 不发送附件 |不和谐.js

如何让 discord bot 等待回复 5 分钟然后发送消息?使用不和谐的 js

Discord bot 在特定频道中发送消息