'How to get a category by its id?

I am making a bot that creates channels. He must create channels in a certain category. I am using guild.create_text_channel(). I haven't found a way to do this in the documentation. Any help would be welcome.



Solution 1:[1]

You can do it with this.

from discord.utils import get

category = get(guild.category_channels, name="CATEGORY_NAME")
await guild.create_text_channel("CHANNEL_NAME", category=category)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Flair