Commands¶
discord_http.commands module¶
- class discord_http.commands.Choice(key, value)¶
Bases:
Generic
[ChoiceT
]Makes it possible to access both the name and value of a choice.
Defaults to a string type
Paramaters¶
- key:
The key of the choice from your dict.
- value:
The value of your choice (the one that is shown to public)
- Parameters:
key (ChoiceT)
value (ChoiceT)
- class discord_http.commands.Command(command, name, description=None, guild_ids=None, guild_install=True, user_install=False, cmd_type=ApplicationCommandType.chat_input, parent=None)¶
Bases:
object
- Parameters:
- autocomplete(name) Callable[[Callable], Callable] ¶
Decorator to set an option as an autocomplete.
The function must at the end, return a Response.send_autocomplete() object.
Example usage
@commands.command() async def ping(ctx, options: str): await ctx.send(f"You chose {options}") @ping.autocomplete("options") async def search_autocomplete(ctx, current: str): return ctx.response.send_autocomplete({ "key": "Value shown to user", "feeling_lucky_tm": "I'm feeling lucky!" })
- property cooldown: CooldownCache | None¶
Returns the cooldown rule of the command if available.
- async run(context, *args, **kwargs) BaseResponse ¶
Runs the command.
- Parameters:
context (
Context
) – The context of the command.*args – The arguments of the command.
**kwargs – The keyword arguments of the command.
- Return type:
BaseResponse
- Returns:
The return type of the command, used by backend.py (Quart)
- Raises:
UserMissingPermissions – User that ran the command is missing permissions.
BotMissingPermissions – Bot is missing permissions.
- class discord_http.commands.Converter(*args, **kwargs)¶
Bases:
Protocol
[ConverterT
]The base class of converting strings to whatever you desire.
Instead of needing to implement checks inside the command, you can use this to convert the value on runtime, both in sync and async mode.
- async convert(ctx, value) ConverterT ¶
The function where you implement the logic of converting the value into whatever you need to be outputted in command.
- class discord_http.commands.Interaction(func, custom_id, *, regex=False)¶
Bases:
object
- class discord_http.commands.PartialCommand(data)¶
Bases:
PartialBase
- Parameters:
data (dict)
- class discord_http.commands.SubGroup(*, name, description=None, guild_ids=None, guild_install=True, user_install=False, parent=None)¶
Bases:
Command
- Parameters:
- command(name=None, *, description=None, guild_ids=None, guild_install=True, user_install=False) Callable[[Callable], SubCommand] ¶
Decorator to add a subcommand to a subcommand group.
- Parameters:
name (
str
|None
) – Name of the command (defaults to the function name)description (
str
|None
) – Description of the command (defaults to the function docstring)guild_ids (
list
[Snowflake
|int
] |None
) – List of guild IDs to register the command inuser_install (
bool
) – Whether the command can be installed by users or notguild_install (
bool
) – Whether the command can be installed by guilds or not
- Return type:
Commands decorators¶
- discord_http.commands.command(name=None, *, description=None, guild_ids=None, guild_install=True, user_install=False) Callable[[Callable], Command] ¶
Decorator to register a command.
- Parameters:
name (
str
|None
) – Name of the command (defaults to the function name)description (
str
|None
) – Description of the command (defaults to the function docstring)guild_ids (
list
[Snowflake
|int
] |None
) – List of guild IDs to register the command inuser_install (
bool
) – Whether the command can be installed by users or notguild_install (
bool
) – Whether the command can be installed by guilds or not
- Return type:
- discord_http.commands.user_command(name=None, *, guild_ids=None, guild_install=True, user_install=False) Callable[[Callable], Command] ¶
Decorator to register a user command.
Example usage
@user_command() async def content(ctx, user: Union[Member, User]): await ctx.send(f"Target: {user.name}")
- Parameters:
name (
str
|None
) – Name of the command (defaults to the function name)guild_ids (
list
[Snowflake
|int
] |None
) – List of guild IDs to register the command inuser_install (
bool
) – Whether the command can be installed by users or notguild_install (
bool
) – Whether the command can be installed by guilds or not
- Return type:
- discord_http.commands.message_command(name=None, *, guild_ids=None, guild_install=True, user_install=False) Callable[[Callable], Command] ¶
Decorator to register a message command.
Example usage
@message_command() async def content(ctx, msg: Message): await ctx.send(f"Content: {msg.content}")
- Parameters:
name (
str
|None
) – Name of the command (defaults to the function name)guild_ids (
list
[Snowflake
|int
] |None
) – List of guild IDs to register the command inuser_install (
bool
) – Whether the command can be installed by users or notguild_install (
bool
) – Whether the command can be installed by guilds or not
- Return type:
- discord_http.commands.group(name=None, *, description=None, guild_ids=None, guild_install=True, user_install=False) Callable[[Callable], SubGroup] ¶
Decorator to register a command group.
- Parameters:
name (
str
|None
) – Name of the command group (defaults to the function name)description (
str
|None
) – Description of the command group (defaults to the function docstring)guild_ids (
list
[Snowflake
|int
] |None
) – List of guild IDs to register the command group inuser_install (
bool
) – Whether the command group can be installed by users or notguild_install (
bool
) – Whether the command group can be installed by guilds or not
- Return type:
- discord_http.commands.locales(translations) Callable[[Callable], Callable] ¶
Decorator to set translations for a command.
_ = Reserved for the root command name and description.
Example usage:
@commands.command(name="ping") @commands.locales({ # Norwegian "no": { "_": ("ping", "Sender en 'pong' melding") "funny": ("morsomt", "Morsomt svar") } }) async def ping(ctx, funny: str): await ctx.send(f"pong {funny}")
- Parameters:
translations (
dict
[Literal
['id'
,'da'
,'de'
,'en-GB'
,'en-US'
,'es-ES'
,'fr'
,'es-419'
,'hr'
,'it'
,'lt'
,'hu'
,'nl'
,'no'
,'pl'
,'pt-BR'
,'ro'
,'fi'
,'sv-SE'
,'vi'
,'tr'
,'cs'
,'el'
,'bg'
,'ru'
,'uk'
,'hi'
,'th'
,'zh-CN'
,'ja'
,'zh-TW'
,'ko'
],dict
[str
,list
[str
] |tuple
[str
] |tuple
[str
,str
]]]) – The translations for the command name, description, and options.- Return type:
- discord_http.commands.describe(**kwargs) Callable ¶
Decorator to set descriptions for a command.
Example usage:
@commands.command() @commands.describe(user="User to ping") async def ping(ctx, user: Member): await ctx.send(f"Pinged {user.mention}")
- discord_http.commands.allow_contexts(*, guild=True, bot_dm=True, private_dm=True) Callable ¶
Decorator to set the places you are allowed to use the command.
Can only be used if the Command has user_install set to True.
- discord_http.commands.cooldown(rate, per, *, type=None) Callable[[Callable], Callable] ¶
Decorator to set a cooldown for a command.
Example usage
@commands.command() @commands.cooldown(1, 5.0) async def ping(ctx): await ctx.send("Pong!")
- Parameters:
rate (
int
) – The number of times the command can be used within the cooldown periodper (
float
) – The cooldown period in secondstype (
BucketType
|None
) – The bucket type to use for the cooldown If not set, it will be using default, which is a global cooldown
- Return type:
- discord_http.commands.choices(**kwargs) Callable ¶
Decorator to set choices for a command.
Example usage:
@commands.command() @commands.choices( options={ "opt1": "Choice 1", "opt2": "Choice 2", ... } ) async def ping(ctx, options: Choice[str]): await ctx.send(f"You chose {choice.value}")
- discord_http.commands.guild_only() Callable ¶
Decorator to set a command as guild only.
This is a alias to two particular functions: - commands.allow_contexts(guild=True, bot_dm=False, private_dm=False) - commands.check(…) (which checks for Context.guild to be available)
- Return type:
- discord_http.commands.default_permissions(*args) Callable ¶
Decorator to set default permissions for a command.
- Return type:
- Parameters:
args (Permissions | str)
- discord_http.commands.has_permissions(*args) Callable ¶
Decorator to set permissions for a command.
Example usage:
@commands.command() @commands.has_permissions("manage_messages") async def ban(ctx, user: Member): ...
- Return type:
- Parameters:
args (Permissions | str)
- discord_http.commands.bot_has_permissions(*args) Callable ¶
Decorator to set permissions for a command.
Example usage:
@commands.command() @commands.bot_has_permissions("embed_links") async def cat(ctx): ...
- Return type:
- Parameters:
args (Permissions | str)
- discord_http.commands.check(predicate) Callable ¶
Decorator to set a check for a command.
Example usage:
def is_owner(ctx): return ctx.author.id == 123456789 @commands.command() @commands.check(is_owner) async def foo(ctx): ...