Niromash
Niromash

Reputation: 15

Delete a channel with a reaction

I need help, I'm looking for a way to delete a channel created automatically by the bot via the "

I present you my code below.

And if by any chance you know how to delete a voice channel using discord.js.

Thank you in advance! Sincerely

ticket.js

https://pastebin.com/rpsbPMNT

close.js

const discord = require("discord.js");
const botconfig = require("../botconfig.json");

module.exports.run = async (bot, message, args) => {

    // Id van category van tickets.
    const categoryId = botconfig.ticketcategory;

    // Als bericht in ticket kanaal is dan verwijder kanaal ander zend bericht
    if (message.channel.parentID == categoryId) {

        message.channel.delete();

    } else {

        message.channel.send("Please do this command in a ticket channel.");

    }

    var embedCloseTicket = new discord.RichEmbed()
        .setTitle("Hello, " + message.channel.name)
        .setDescription("Your ticket is marked as **complete**. Do you want to make a new one then do !ticket")
        .setFooter("Ticket closed!");

    message.author.send(embedCloseTicket);

}

module.exports.help = {
    name: "close",
    aliases: ["ticketclose", "ticketsupportclose"]
}

Upvotes: 0

Views: 1112

Answers (1)

Eduardo Espinoza
Eduardo Espinoza

Reputation: 16

You need to create a reaction collector.

//your code...
message.author.send(embedCloseTicket).then((msg) => {
msg.react("the emoji")
}).then(r => {
const filter = (reaction, user) => reaction.emoji.name === "emoji" && 
user.id === message.author.id;
//create the collector
const collectorForU = msg.createReactionCollector(filter, {time: 1000/*time 
in ms*/});
collectorForU.on("collect", r => {
msg.channel.delete()      
})
})

I didn't try this code, but I think it must work.

Upvotes: 0

Related Questions