discord_slash.context module
- class discord_slash.context.SlashContext(_http: discord_slash.http.SlashCommandRequest, _json: dict, _discord: Union[discord.client.Client, discord.ext.commands.bot.Bot], logger)
Bases:
object
Context of the slash command.
Kinda similar with discord.ext.commands.Context.
Warning
Do not manually init this model.
- Variables
message – Message that invoked the slash command.
name – Name of the command.
args – List of processed arguments invoked with the command.
kwargs – Dictionary of processed arguments invoked with the command.
subcommand_name – Subcommand of the command.
subcommand_group – Subcommand group of the command.
interaction_id – Interaction ID of the command message.
command_id – ID of the command.
bot – discord.py client.
_http –
http.SlashCommandRequest
of the client._logger – Logger instance.
deferred – Whether the command is current deferred (loading state)
_deferred_hidden – Internal var to check that state stays the same
responded – Whether you have responded with a message to the interaction.
guild_id – Guild ID of the command message. If the command was invoked in DM, then it is
None
author_id – User ID representing author of the command message.
channel_id – Channel ID representing channel of the command message.
author – User or Member instance of the command invoke.
- property deffered
- property guild: Optional[discord.guild.Guild]
Guild instance of the command invoke. If the command was invoked in DM, then it is
None
- Returns
Optional[discord.Guild]
- property channel: Optional[Union[discord.channel.TextChannel, discord.channel.DMChannel]]
Channel instance of the command invoke.
- Returns
Optional[Union[discord.abc.GuildChannel, discord.abc.PrivateChannel]]
- async defer(hidden: bool = False)
‘Defers’ the response, showing a loading state to the user
- Parameters
hidden – Whether the deferred response should be ephemeral . Default
False
.
- async send(content: str = '', *, embed: Optional[discord.embeds.Embed] = None, embeds: Optional[List[discord.embeds.Embed]] = None, tts: bool = False, file: Optional[discord.file.File] = None, files: Optional[List[discord.file.File]] = None, allowed_mentions: Optional[discord.mentions.AllowedMentions] = None, hidden: bool = False, delete_after: Optional[float] = None) discord_slash.model.SlashMessage
Sends response of the slash command.
Warning
Since Release 1.0.9, this is completely changed. If you are migrating from older version, please make sure to fix the usage.
You can’t use both
embed
andembeds
at the same time, also applies tofile
andfiles
.If you send files in the initial response, this will defer if it’s not been deferred, and then PATCH with the message
- Parameters
content (str) – Content of the response.
embed (discord.Embed) – Embed of the response.
embeds (List[discord.Embed]) – Embeds of the response. Maximum 10.
tts (bool) – Whether to speak message using tts. Default
False
.file (discord.File) – File to send.
files (List[discord.File]) – Files to send.
allowed_mentions (discord.AllowedMentions) – AllowedMentions of the message.
hidden (bool) – Whether the message is hidden, which means message content will only be seen to the author.
delete_after (float) – If provided, the number of seconds to wait in the background before deleting the message we just sent. If the deletion fails, then it is silently ignored.
- Returns
Union[discord.Message, dict]