Bagaimana cara membuatnya sehingga ketika seseorang bereaksi dengan emoji pertama dalam perintah ini, bot menghapus pesan dan mengirimkannya ke saluran lain?

Kode saat ini:

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"
};
3
aakhilv 7 Juli 2020, 04:46

1 menjawab

Jawaban Terbaik

Anda dapat menggunakan acara awaitReactions, createReactionCollector atau messageReactionAdd, saya pikir awaitReactions adalah opsi terbaik di sini karena dua lainnya untuk tujuan yang lebih global,

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 
        });
});
1
5 Oktober 2020, 21:12