Skip to content Skip to sidebar Skip to footer

How To Delete A Discord Channel Using Python?

@Bot.command(pass_context= True) async def complete(ctx): guild = ctx.message.guild id_admin = discord.Role.id=658306078928273408 overwrites = { id_admin: disco

Solution 1:

You can use the GuildChannel.delete method, with any subclass of GuildChannel.
You can retrieve the TextChannel the message was sent in using Context.channel.

You should not be modifying the attributes of discord.py classes, and you should be referencing the attributes of specific objects/instances of those classes.


Solution 2:

@Harmon758 gives a very good idea of how the delete command should be called but for anyone not familiar with discord API, here is how I handle delete channel request:

@bot.command(name='delete-channel', help='delete a channel with the specified name')
async def delete_channel(ctx, channel_name):
   # check if the channel exists
   existing_channel = discord.utils.get(guild.channels, name=channel_name)
   
   # if the channel exists
   if existing_channel is not None:
      await existing_channel.delete()
   # if the channel does not exist, inform the user
   else:
      await ctx.send(f'No channel named, "{channel_name}", was found')

Post a Comment for "How To Delete A Discord Channel Using Python?"