Where is InvalidChannelPermissions exception in pycord?

I have a bot that should join a voice channel via slash command. But then target voice channel reaches it’s user limit, and command called by user, i’m getting discord.errors.ApplicationCommandInvokeError: Application Command raised an exception:
InvalidChannelPermissions: There are currently too many users in this channel. <2/2>
I know why is that, and i just need to make a handling of that error, but i didn’t found that exception (InvalidChannelPermissions) anywhere in the docs of pycord or even in files.

I need to do something like:

if isinstance(error, InvalidChannelPermissions):
   # handle error

in my on_application_command_error event, but i can’t find where is InvalidChannelPermissions.

>Solution :

In the Pycord library, the InvalidChannelPermissions exception is not directly available. However, you can catch this exception by using the base DiscordException and checking for the error message. Here’s an example:

from discord.errors import DiscordException

async def on_application_command_error(ctx, error):
    if isinstance(error, DiscordException):
        if "InvalidChannelPermissions" in str(error) or "are currently too many users in this channel" in str(error):
            # handle error

Here, we catch the base DiscordException and check if the error message contains "InvalidChannelPermissions" or "are currently too many users in this channel". If it does, you can handle the error accordingly.

Leave a Reply