Interactions API Reference

This section outlines all the available tools for interaction based commands (application commands, UI kit, etc.)

Models

MaxConcurrency

Attributes
class discord_tools.app_commands.MaxConcurrency(number, *, per)[source]

Represents a maximum concurrency object for application commands.

number

The number of times allowed for the command to be executed concurrently.

Type:

int

per

The bucket to use for this max concurrency object.

Type:

BucketType

Parameters:

Enumerations

BucketType

class discord_tools.app_commands.BucketType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Specifies a type of bucket for, e.g. a cooldown.

This works in a similar way as discord.ext.commands.BucketType, but designed for interactions.

To pass a BucketType to a application commands cooldown you must do the following:

@app_commands.command(...)
@app_commands.checks.cooldown(rate, per, key=BucketType.default)  # Change the bucket type as desired
async def my_command(...):
    ...
default = 0

The default bucket operates on a global basis.

user = 1

The user bucket operates on a per-user basis.

guild = 2

The guild bucket operates on a per-guild basis.

channel = 3

The channel bucket operates on a per-channel basis.

member = 4

The member bucket operates on a per-member basis.

category = 5

The category bucket operates on a per-category basis.

role = 6

The role bucket operates on a per-role basis.

Exceptions

exception discord_tools.app_commands.MissingSKU(skus, *args)[source]

An exception raised when a command invoker is missing a SKU.

skus

The SKUs that are missing. These are the same as the ones provided in has_skus.

Type:

List[Union[discord.abc.Snowflake, str, int]]

Parameters:
exception discord_tools.app_commands.MaxConcurrencyReached(number, per)[source]

An exception raised when a command has reached its max concurrency.

number

The maximum number of concurrent invokers allowed.

Type:

int

per

The bucket type passed to the max_concurrency() decorator.

Type:

BucketType

Parameters:

Checks

discord_tools.app_commands.max_usages(limit, bucket)[source]

A decorator that adds a limit of usages to a command.

Parameters:
  • limit (int) – The amount of allowed usages before the command is no longer usable.

  • bucket (BucketType) – The bucket in which the usages are restricted by.

discord_tools.app_commands.has_skus(*sku_ids)[source]

A decorator that checks if the interaction has all the provided skus.

Parameters:

sku_ids (Union[int, str, Snowflake]) – The SKU IDs to check for.

discord_tools.app_commands.max_concurrency(number, per=BucketType.default)[source]

A decorator that adds a maximum concurrency to a discord.app_commands.Command or its subclasses.

This enabled you to only allow a certain number of command invocations at the same time, for example if a command takes too long or if only one user can use it at a time. This differs from a cooldown in that there is no set waiting period or token bucket – only a set number of people can run the command.

This is the application command variant, for prefixed commands see discord.ext.commands.max_concurrency().

Unlike discord.ext.commands.max_concurrency(), this decorator cannot wait for the commands to finish because of the 3 seconds limit to respond to an interaction.

Parameters:
  • number (int) – The maximum number of concurrent invocations.

  • per (BucketType) – The bucket that this concurrency is based on, e.g. BucketType.guild would allow it to be used up to number times per guild.