J
J
Javasavr2019-10-09 11:32:03
Node.js
Javasavr, 2019-10-09 11:32:03

How to delete a channel with a specific name in Discord?

There is a bot for Discord, written in NodeJS and the Discord.JS framework, I was able to implement the creation of channels with a certain number of slots, now I need to implement the removal of a channel with a specific name, but the Discord.JS documentation does not have a detailed description of deleting a channel with a specific name
. Code:

const Discord = require("../discord.js");
const client = new Discord.Client();

client.on("ready", () => {
    console.log(`Logged in as ${client.user.tag}!`);
});

client.on("message", msg => {
    var command = msg.content.split(" ");
    switch (command[0].toLowerCase()) {
        case '!-help':
            msg.reply(
                "```" +
                "!-createchannel *name* *slots* \n" +
                "```"
            );
            break;
        case '!-hi':
            msg.reply("Hi! I am super cool bot!");
            break;
        case '!-createchannel':
            makeChannel(msg, commandArray[1], commandArray[2]) 
            msg.reply("The channel is created.");
            break;
    }
});

function makeChannel(message, name, limit){
    var server = message.guild;

    server.createChannel(name, "voice")
    .then(channel => {
        channel.userLimit = limit;
        let category = server.channels.find(c => c.name == "Игровые" && c.type == "category");

        if (!category) throw new Error("Category channel does not exist");
        channel.setParent(category.id);
    }).catch(console.error);
};

client.login(process.argv[2]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Neverov, 2019-10-09
@Javasavr

You go through all the channels in the same way, look at their name, delete the one you need .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question