Reputation: 29
I'm actually making a discord bot with discord.js, and I was wondering how to do a command to delete a specific channel with a name
ex : !delete #general
I already tried to do the following:
if (command == "delete") {
channel.delete(args.join(" "))
}
but it doesn't work so I'm kinda stuck thank you
Upvotes: 1
Views: 26443
Reputation: 1
use:
message.channel.delete();
you can put it in client.on like this
client.on("message", message => {
message.channel.delete()
})
Upvotes: 0
Reputation: 1
If you want to delete a specific channel with eval command then use this code
t!eval
const fetchedChannel = message.guild.channels.cache.get("CHANNEL_ID");
fetchedChannel.delete();
Upvotes: 0
Reputation: 66
That code now is old if you are going to up-date(with discord.js v12) it try with:
const fetchedChannel = message.guild.channels.cache.get(channel_id);
fetchedChannel.delete();
Upvotes: 4
Reputation: 2990
You have to use the .delete
method to delete a guild textchannel.
I added a new variable fetchedChannel
which tries to fetch the channel by its name from args
.
Try to use the following code:
const fetchedChannel = message.guild.channels.find(r => r.name === args.join(' '));
if (command === 'delete') {
fetchedChannel.delete();
}
Upvotes: 6