How do you make a Nextcord bot tell a user that they have insufficient permissions?

Viewed 85

How would you make a Nextcord bot send a message in chat telling a user that they have insufficient permissions when using @application_checks? Eg:

@bot.slash_command()
@application_checks.has_permissions(manage_messages=True)
async def testperms(interaction: Interaction):
    await interaction.response.send_message('You can manage messages.')

How would you make it tell the user they Can't manage messages (ect) if they don't have the permissions?

1 Answers

Explanation

Like a regular message command, you can check for any errors raised by your checks or slash command using the following decorator: @testperms.error

In this error handling function, you can check if the error raised is of type ApplicationMissingPermissions and then send an error message in response to the interaction.

Code

@bot.slash_command()
@application_checks.has_permissions(manage_messages=True)
async def testperms(interaction: Interaction):
    await interaction.response.send_message('You can manage messages.')


@testperms.error
async def on_testperms_error(interaction: Interaction, error):
    if isinstance(error, application_checks.ApplicationMissingPermissions):
        await interaction.response.send_message("You cannot manage messages.")
    else:
        raise error

Reference

ApplicationMissingPermissions

application_checks

Related