#Get_Channel works with categories but how can I safely confirm that the type returned is a category

1 messages · Page 1 of 1 (latest)

azure vigil
#
category = inter.guild.get_channel(1274758658525364329) 

newChannel = await inter.guild.create_text_channel(name=f"New Channel", category=category )

Argument of type "GuildChannel" cannot be assigned to parameter "category" of type "CategoryChannel | None" in function "create_text_channel"

This problem is raised by Pylance and we see get_channel has no chance of returning a category as per the return values:

    def get_channel(self, channel_id: int, /) -> Optional[GuildChannel]:
        """Returns a channel with the given ID.

Any response in advance is appreciated.

mild knoll
#

to verify what you get from get_channel is a category, you can simply just make sure with isinstance(channel, disnake.CategoryChannel)

azure vigil
mild knoll
#

all good, no worries ^^