javascript - 如何让机器人在 react 后发送消息到另一个 channel | Discord.js

标签 javascript node.js bots discord discord.js

我该如何做到,当有人对此命令中的第一个表情符号使用react时,机器人会删除该消息并将其发送到另一个 channel ?

当前代码:

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"
};

最佳答案

您可以使用 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 
        });
});

关于javascript - 如何让机器人在 react 后发送消息到另一个 channel | Discord.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62766934/

相关文章:

Python discord bot 警告特定的人

Facebook 爬虫机器人崩溃网站

javascript - 做 Sequelize 关联 在数据库端做任何事情

javascript - 三维 Javascript 数组

javascript - 如何在完成之前获取异步函数的状态?

javascript - Promise 对象内的 setTimeout

javascript - AJAX 调用重新加载仅有效一次

javascript - 如何在 Angular 单击按钮时显示不受欢迎的复选框?

javascript - WooCommerce API 授权在 node.js 应用程序中不起作用

email - 如何保护网站上的电子邮件地址免受现代支持 JS 的机器人的攻击?