2 Framework App Command Check Decorators
Mrcoolgamer11 edited this page 2026-11-22 16:07:10 +00:00

This page is generated from docs/framework_checks_app_commands.rst - please edit the source file instead of this page.

App Command Check Decorators

The following are all decorators for app commands, which add restrictions to where and when they can be run.

redbot.core.app_commands.checks.admin()

Restrict the command to users with the admin role.

NOTE

This is different from the permission system that Discord provides for application commands. This is done entirely locally in the program rather than being handled by Discord.

redbot.core.app_commands.checks.admin_or_can_manage_channel(, allow_thread_owner=False)

Restrict the command to users with the admin role or permissions to manage channel.

This check properly resolves the permissions for discord.Thread as well.

NOTE

This is different from the permission system that Discord provides for application commands. This is done entirely locally in the program rather than being handled by Discord.

  • Parameters: allow_thread_owner (bool) -- If True, the command will also be allowed to run if the author is a thread owner. This can, for example, be useful to check if the author can edit a channel/thread's name as that, in addition to members with manage channel/threads permission, can also be done by the thread owner.

redbot.core.app_commands.checks.admin_or_permissions(**perms)

Restrict the command to users with the admin role or these permissions.

NOTE

This is different from the permission system that Discord provides for application commands. This is done entirely locally in the program rather than being handled by Discord.

redbot.core.app_commands.checks.bot_can_manage_channel(, allow_thread_owner=False)

Complain if the bot is missing permissions to manage channel.

This check properly resolves the permissions for discord.Thread as well.

NOTE

This is different from the permission system that Discord provides for application commands. This is done entirely locally in the program rather than being handled by Discord.

  • Parameters: allow_thread_owner (bool) -- If True, the command will also be allowed to run if the bot is a thread owner. This can, for example, be useful to check if the bot can edit a channel/thread's name as that, in addition to members with manage channel/threads permission, can also be done by the thread owner.

redbot.core.app_commands.checks.bot_can_react()

Complain if the bot is missing permissions to react.

This check properly resolves the permissions for discord.Thread as well.

NOTE

This is different from the permission system that Discord provides for application commands. This is done entirely locally in the program rather than being handled by Discord.

redbot.core.app_commands.checks.bot_has_permissions(**perms)

Similar to has_permissions() except checks if the bot itself has the permissions listed. This relies on discord.Interaction.app_permissions.

This check raises a special exception, BotMissingPermissions that is inherited from CheckFailure.

Versionadded

Added in version 2.0.

redbot.core.app_commands.checks.bot_in_a_guild()

Deny the command if the bot is not in a guild.

NOTE

This is different from the permission system that Discord provides for application commands. This is done entirely locally in the program rather than being handled by Discord.

redbot.core.app_commands.checks.can_manage_channel(, allow_thread_owner=False)

Restrict the command to users with permissions to manage channel.

This check properly resolves the permissions for discord.Thread as well.

NOTE

This is different from the permission system that Discord provides for application commands. This is done entirely locally in the program rather than being handled by Discord.

  • Parameters: allow_thread_owner (bool) -- If True, the command will also be allowed to run if the author is a thread owner. This can, for example, be useful to check if the author can edit a channel/thread's name as that, in addition to members with manage channel/threads permission, can also be done by the thread owner.

redbot.core.app_commands.checks.cooldown(rate, per, , key=...)

A decorator that adds a cooldown to a command.

A cooldown allows a command to only be used a specific amount of times in a specific time frame. These cooldowns are based off of the key function provided. If a key is not provided then it defaults to a user-level cooldown. The key function must take a single parameter, the discord.Interaction and return a value that is used as a key to the internal cooldown mapping.

The key function can optionally be a coroutine.

If a cooldown is triggered, then CommandOnCooldown is raised to the error handlers.

Examples

Setting a one per 5 seconds per member cooldown on a command:

@tree.command()
@app_commands.checks.cooldown(1, 5.0, key=lambda i: (i.guild_id, i.user.id))
async def test(interaction: discord.Interaction):
    await interaction.response.send_message('Hello')

@test.error
async def on_test_error(interaction: discord.Interaction, error: app_commands.AppCommandError):
    if isinstance(error, app_commands.CommandOnCooldown):
        await interaction.response.send_message(str(error), ephemeral=True)
  • Parameters:
    • rate (int) -- The number of times a command can be used before triggering a cooldown.
    • per (float) -- The amount of seconds to wait for a cooldown when it's been triggered.
    • key (Optional[Callable[[discord.Interaction], collections.abc.Hashable]]) -- A function that returns a key to the mapping denoting the type of cooldown. Can optionally be a coroutine. If not given then defaults to a user-level cooldown. If None is passed then it is interpreted as a "global" cooldown.

redbot.core.app_commands.checks.dynamic_cooldown(factory, , key=...)

A decorator that adds a dynamic cooldown to a command.

A cooldown allows a command to only be used a specific amount of times in a specific time frame. These cooldowns are based off of the key function provided. If a key is not provided then it defaults to a user-level cooldown. The key function must take a single parameter, the discord.Interaction and return a value that is used as a key to the internal cooldown mapping.

If a factory function is given, it must be a function that accepts a single parameter of type discord.Interaction and must return a Cooldown or None. If None is returned then that cooldown is effectively bypassed.

Both key and factory can optionally be coroutines.

If a cooldown is triggered, then CommandOnCooldown is raised to the error handlers.

Examples

Setting a cooldown for everyone but the owner.

def cooldown_for_everyone_but_me(interaction: discord.Interaction) -> Optional[app_commands.Cooldown]:
    if interaction.user.id == 80088516616269824:
        return None
    return app_commands.Cooldown(1, 10.0)

@tree.command()
@app_commands.checks.dynamic_cooldown(cooldown_for_everyone_but_me)
async def test(interaction: discord.Interaction):
    await interaction.response.send_message('Hello')

@test.error
async def on_test_error(interaction: discord.Interaction, error: app_commands.AppCommandError):
    if isinstance(error, app_commands.CommandOnCooldown):
        await interaction.response.send_message(str(error), ephemeral=True)
  • Parameters:
    • factory (Optional[Callable[[discord.Interaction], Optional[Cooldown]]]) -- A function that takes an interaction and returns a cooldown that will apply to that interaction or None if the interaction should not have a cooldown.
    • key (Optional[Callable[[discord.Interaction], collections.abc.Hashable]]) -- A function that returns a key to the mapping denoting the type of cooldown. Can optionally be a coroutine. If not given then defaults to a user-level cooldown. If None is passed then it is interpreted as a "global" cooldown.

redbot.core.app_commands.checks.guildowner()

Restrict the command to the guild owner.

NOTE

This is different from the permission system that Discord provides for application commands. This is done entirely locally in the program rather than being handled by Discord.

redbot.core.app_commands.checks.guildowner_or_permissions(**perms)

Restrict the command to the guild owner or users with these permissions.

NOTE

This is different from the permission system that Discord provides for application commands. This is done entirely locally in the program rather than being handled by Discord.

redbot.core.app_commands.checks.has_any_role(*items)

A check() that is added that checks if the member invoking the command has any of the roles specified. This means that if they have one out of the three roles specified, then this check will return True.

Similar to has_role(), the names or IDs passed in must be exact.

This check raises one of two special exceptions, MissingAnyRole if the user is missing all roles, or NoPrivateMessage if it is used in a private message. Both inherit from CheckFailure.

Versionadded

Added in version 2.0.

NOTE

This is different from the permission system that Discord provides for application commands. This is done entirely locally in the program rather than being handled by Discord.

  • Parameters: items (List[Union[str, int]]) -- An argument list of names or IDs to check that the member has roles wise.

Example

@tree.command()
@app_commands.checks.has_any_role('Library Devs', 'Moderators', 492212595072434186)
async def cool(interaction: discord.Interaction):
    await interaction.response.send_message('You are cool indeed')

redbot.core.app_commands.checks.has_permissions(**perms)

A check() that is added that checks if the member has all of the permissions necessary.

Note that this check operates on the permissions given by discord.Interaction.permissions.

The permissions passed in must be exactly like the properties shown under discord.Permissions.

This check raises a special exception, MissingPermissions that is inherited from CheckFailure.

Versionadded

Added in version 2.0.

NOTE

This is different from the permission system that Discord provides for application commands. This is done entirely locally in the program rather than being handled by Discord.

  • Parameters: **perms (bool) -- Keyword arguments denoting the permissions to check for.

Example

@tree.command()
@app_commands.checks.has_permissions(manage_messages=True)
async def test(interaction: discord.Interaction):
    await interaction.response.send_message('You can manage messages.')

redbot.core.app_commands.checks.has_role(item,)

A check() that is added that checks if the member invoking the command has the role specified via the name or ID specified.

If a string is specified, you must give the exact name of the role, including caps and spelling.

If an integer is specified, you must give the exact snowflake ID of the role.

This check raises one of two special exceptions, MissingRole if the user is missing a role, or NoPrivateMessage if it is used in a private message. Both inherit from CheckFailure.

Versionadded

Added in version 2.0.

NOTE

This is different from the permission system that Discord provides for application commands. This is done entirely locally in the program rather than being handled by Discord.

  • Parameters: item (Union[int, str]) -- The name or ID of the role to check.

redbot.core.app_commands.checks.is_owner()

Restrict the command to bot owners.

You probably should not use this check, since slash commands are not designed to be owner only.

NOTE

This is different from the permission system that Discord provides for application commands. This is done entirely locally in the program rather than being handled by Discord.

redbot.core.app_commands.checks.mod()

Restrict the command to users with the mod role.

NOTE

This is different from the permission system that Discord provides for application commands. This is done entirely locally in the program rather than being handled by Discord.

redbot.core.app_commands.checks.mod_or_can_manage_channel(, allow_thread_owner=False)

Restrict the command to users with the mod role or permissions to manage channel.

This check properly resolves the permissions for discord.Thread as well.

NOTE

This is different from the permission system that Discord provides for application commands. This is done entirely locally in the program rather than being handled by Discord.

  • Parameters: allow_thread_owner (bool) -- If True, the command will also be allowed to run if the author is a thread owner. This can, for example, be useful to check if the author can edit a channel/thread's name as that, in addition to members with manage channel/threads permission, can also be done by the thread owner.

redbot.core.app_commands.checks.mod_or_permissions(**perms)

Restrict the command to users with the mod role or these permissions.

NOTE

This is different from the permission system that Discord provides for application commands. This is done entirely locally in the program rather than being handled by Discord.