简体   繁体   中英

discord.js react to a message and delete the message channel

I'm trying to make a command that sends a message to a selected channel, and I'm trying to create a system where if you react on the reaction that the bot creates on its message, it deletes that channel. Heres the code:

const Discord = require('discord.js')
const { MessageEmbed } = require('discord.js');
module.exports = {
    name: 'rejeitar',
    category: 'Premium',
    description: 'Rejeitar alguem na org ',
  
    run: async (client, message, args, user, guild) => {
        if(message.member.roles.cache.some(r => r.name === "[🚬] Gestor tickets")) {
            
            let member = message.mentions.members.first();
            const channel = message.mentions.channels.first();

        ////---------------LOG EMBED-------------/////
            
            const Rejeitado = new MessageEmbed()
                .setColor('#15ff00')
                .setTitle('**📝❱Infelizmente,não foste aceite nos Peaky.**')
                .setDescription('**Tenta novamente mais tarde**')
                .addFields(
                  { name: '**💼❱Rejeitado pelo staff**', value: `${message.author.tag}` },
                  { name: '**🕒❱Data**', value: `${message.createdAt}` },
                  { name: '**👨‍🦲❱Membro Rejeitado**', value:`${member}`, inline: true },
                )
                .setTimestamp()
                .setFooter({ text: 'Bot feito por chain' });
      
            const lastemoji = ("✅")
            const sentMessage = await message.channel.send("Clica no ✅ para fechar o ticket");

            const sendembed1 = await message.channel.send({ embeds: [Rejeitado] })

            message.react("✅")
      
            if(channel && member ) { 
                channel.send({ embeds: [Rejeitado] });
                channel.send(`${member} Clica no ✅ para fechar o ticket`)
                client.on("messageReactionAdd", ({ message: { channel } }, user) => {
                    channel.delete
                })
            } else message.channel.send("**ERRO**\nVerifica se podes usar o comando ou se esta correto!(!Rejeitar #ticket  @pessoa Rejeitada )")
        }   
    
    }
}

The problem is that when I react to it, nothing happens.

In order to achieve that you need to create an awaitReactions() collector on the message that you want the users to react to.

The collector in your case would look something of the sorts:

const filter = (reaction, user) => {
    return reaction.emoji.name === '✅' && user.id === message.author.id;
  };
// Increase or decrease the time based on your needs.
const collector = message.createReactionCollector({ filter, time: 15000, max: 1 });

After that, handle the reactions:

collector.on("collect", (reaction, user) => {

/* Because of the way we defined our filter, there is no need to check
if the user reacted with any other emoji than the ✅ */

channel.delete();
})

// and if the user doesn't react with anything in the time limit
collector.on('end', collected => {
 if(collected.size < 1) {
  return message.channel.send("You didn't react with anything, the collector has ended.")
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM