Hassan Serhan
Hassan Serhan

Reputation: 402

How to delete the channels of a category deleted by the user on Discord?

I want to delete all channels of a category deleted by the user on Discord, using python. I've just found this function on_guild_channel_delete(channel) but it doesn't work as I want cause the channels are found after the category was deleted.

Thanks in advance.

Upvotes: 0

Views: 2338

Answers (1)

Nurqm
Nurqm

Reputation: 4743

If you are going to use that bot on your own server and if all of your channels will be in any category, you can use that way:

@client.event
async def on_guild_channel_delete(channel):
    for chn in channel.guild.channels:
        if not chn.category and not isinstance(chn, discord.channel.CategoryChannel):
            await i.delete()

With this, it will delete all the channels that has no category when a category or channel is deleted. This isn't a perfect solution but as far as I know, this is the only way to do this.

Upvotes: 1

Related Questions