简体   繁体   English

discord.js 对消息做出反应并删除消息通道

[英]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.为了实现这一点,您需要在您希望用户做出反应的消息上创建一个awaitReactions()收集器。

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.")
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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