Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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

@bot.event
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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading