问题
I'm creating a bot that manages a server to get used to JavaScript and the Discord.js library. I tried deleting a channel using this code, but it didn't work.
guild.channel.delete('Making room for new channels')
.then(deleted => console.log(`Deleted ${deleted.name} to make room for new channels`))
.catch(console.error);
I've already tried to replace the first line with channel.delete and channel.guild.delete, but I kind of gave up since I have no clue on how to make it delete every channel in the guild.
As bad as this sounds, I'm not trying to destroy any discord server.
Thanks in advance.
回答1:
If you want your bot to delete every single channel in a guild, do this:
guild.channels.forEach(c => c.delete());
Your attempt failed to work since channel isn't a property of the Guild Class. So what I'm doing is accessing the channels collection of the Guild Class, which contains every single Channel of that Guild. Then we can iterate over each channel and use the delete method, which is part of every GuildChannel Object.
来源:https://stackoverflow.com/questions/52524990/deleting-single-channel-all-channels-does-not-work