Search code examples
pythondiscord

How do delete categories in discord py?


Im working on a bot that will delete all channels and categories in a guild then add new channels, roles and categories kind of like a server set up bot. How ever I cant figure out how to remove categories. Any help is appreciated!


Solution

  • Since you haven't provided an approach, I really don't know if you've done any research at all. There is a whole simple solution to this.

    Depending on which method you work with, you have to rewrite the code a bit.

    Look at the following:

    @client.command()
    async def delcat(ctx):
        for category in ctx.guild.categories: # Get all the categories
            await category.delete() # Delete them in the loop
        print("Deleted all categories.") # Print the result
    

    Here we go with a for-loop over all categories in the ctx.guild, as where the command was executed. In this loop we then delete all categories and at the end we get our print statement that everything worked.