Documentation#
- class discohook.Client(*, application_id: Union[int, str], public_key: str, token: str, route: str = '/interactions', **kwargs)[source]#
Bases:
FastAPI
The base client class for discohook.
- Parameters:
application_id (int | str) – The application ID of the bot.
public_key (str) – The public key of the bot.
token (str) – The token of the bot.
route (str) – The route to listen for interactions on.
**kwargs – Keyword arguments to pass to the FastAPI instance.
- add_commands(*commands: Union[ApplicationCommand, Any])[source]#
Add commands to the client.
- Parameters:
*commands (ApplicationCommand) – The commands to add to the client.
- async as_user() ClientUser [source]#
Get the client as partial user.
- Returns:
The client as partial user.
- Return type:
ClientUser
- command(name: str, description: Optional[str] = None, *, options: Optional[List[Option]] = None, permissions: Optional[List[Permissions]] = None, dm_access: bool = True, category: ApplicationCommandType = ApplicationCommandType.slash)[source]#
A decorator to register a command.
- Parameters:
name (str) – The name of the command.
description (Optional[str]) – The description of the command. Does not apply to user & message commands.
options (Optional[List[Option]]) – The options of the command. Does not apply to user & message commands.
permissions (Optional[List[Permissions]]) – The default permissions of the command.
dm_access (bool) – Whether the command can be used in DMs. Defaults to True.
category (AppCmdType) – The category of the command. Defaults to slash commands.
- async create_webhook(channel_id: str, *, name: str, image_base64: Optional[str] = None)[source]#
Create a webhook in a channel. :param channel_id: The ID of the channel to create the webhook in. :type channel_id: str :param name: The name of the webhook. :param image_base64: The base64 encoded image of the webhook.
- Return type:
Webhook
- custom_id_parser(coro: Callable)[source]#
A decorator to register a dev defined custom id parser. :param coro: :type coro: Callable
- async delete_command(command_id: str)[source]#
Delete a command from the client.
- Parameters:
command_id (str) –
- async fetch_guild(guild_id: str) Optional[Guild] [source]#
Fetches the guild of given id.
- Return type:
- async fetch_webhook(webhook_id: str, *, webhook_token: Optional[str] = None)[source]#
Fetch a webhook from the client. :param webhook_id: The ID of the webhook to fetch. :type webhook_id: str :param webhook_token: The token of the webhook to fetch. :type webhook_token: Optional[str]
- Return type:
Webhook
- load_components(view: View)[source]#
Loads multiple components into the client. Do not use this method unless you know what you are doing.
- Parameters:
view (View) – The view to load components from.
- load_modules(directory: str)[source]#
Loads multiple command form modules in a directory.
- Parameters:
directory (str) – The directory to load the modules from.
- on_error(coro: Callable)[source]#
A decorator to register a global error handler.
- Parameters:
coro (Callable) – The coroutine to register as the global error handler. Must take 2 parameters:error and data.
- async send_message(channel_id: str, content: Optional[str] = None, *, tts: bool = False, embed: Optional[Embed] = None, embeds: Optional[List[Embed]] = None, file: Optional[File] = None, files: Optional[List[File]] = None)[source]#
Send a message to a channel using the ID of the channel.
- Parameters:
channel_id (str) – The ID of the channel to send the message to.
content (Optional[str]) – The content of the message.
tts (bool) – Whether the message should be sent using text-to-speech. Defaults to False.
embed (Optional[Embed]) – The embed to send with the message.
embeds (Optional[List[Embed]]) – A list of embeds to send with the message. Maximum of 10.
file (Optional[File]) – A file to be sent with the message
files (Optional[List[File]]) – A list of files to be sent with message.
- class discohook.User(data: Dict[str, Any], client: Client)[source]#
Bases:
object
Represents a discord user.
Properties#
- id:
str
The unique ID of the user.
- name:
str
The name of the user.
- discriminator:
str
The discriminator of the user.
- avatar:
Asset
The avatar of the user.
- system:
bool
Whether the user is a system user.
- bot:
bool
Whether the user is a bot.
- mfa_enabled:
bool
Whether the user has MFA enabled.
- locale: Optional[
str
] The locale of the user.
- verified:
bool
Whether the user is verified.
- email: Optional[
str
] The email of the user.
- premium_type: Optional[
int
] The premium type of the user.
- public_flags: Optional[
int
] The public flags of the user.
- mention:
str
Returns a string that allows you to mention the user.
- async send(content: str, *, tts: bool = False, embed: Optional[Embed] = None, embeds: Optional[List[Embed]] = None, file: Optional[File] = None, files: Optional[List[File]] = None) Dict[str, Any] [source]#
Sends a message to the user.
- Parameters:
content (
str
) – The content of the message.tts (
bool
) – Whether the message should be sent using text-to-speech.embed (Optional[
Embed
]) – The embed to be sent with the message.embeds (Optional[
List`[:class:`Embed
]`]) – The embeds to be sent with the message.file (Optional[
File
]) – The file to be sent with the message.files (Optional[
List`[:class:`File
]`]) – The files to be sent with the message.
- id:
- class discohook.Member(data: Dict[str, Any], client: Client)[source]#
Bases:
User
Represents a member of a guild sent with an interaction, subclassed from
User
.- async add_role(role_id: str)[source]#
Add a role to the member.
- Parameters:
role_id (str) – The ID of the role.
- async ban(*, delete_message_seconds: int = 0)[source]#
Ban the member.
- Parameters:
delete_message_seconds (int) – The number of days to delete messages for.
- property mention: str#
Returns a string that allows you to mention the member.
- class discohook.PartialGuild(guild_id: str, client: Client)[source]#
Bases:
object
Represents a partial guild.
- async create_channel(name: str, *, type: ChannelType = ChannelType.guild_text, topic: Optional[str] = None, bitrate: Optional[int] = None, user_limit: Optional[int] = None, rate_limit_per_user: Optional[int] = None, position: Optional[int] = None, permission_overwrites: Optional[List[Dict[str, Any]]] = None, parent_id: Optional[str] = None, nsfw: Optional[bool] = None, rtc_region: Optional[str] = None, video_quality_mode: Optional[int] = None, default_auto_archive_duration: Optional[int] = None, default_reaction_emoji: Optional[PartialEmoji] = None, available_tags: Optional[List[Dict[str, Any]]] = None, default_sort_order: Optional[int] = None) Channel [source]#
Creates a channel in the guild. Requires the MANAGE_CHANNELS permission.
- Parameters:
name (str) – Name of the channel (2-100 characters)
type (ChannelType) – The type of channel
topic (str) – Channel topic (0-1024 characters)
bitrate (int) – The bitrate (in bits) of the voice channel (voice only)
user_limit (int) – The user limit of the voice channel (voice only)
rate_limit_per_user (int) – Amount of seconds a user has to wait before sending another message (0-21600) bots, as well as users with the permission manage_messages or manage_channel, are unaffected
position (int) – Sorting position of the channel
permission_overwrites (List[Dict[str, Any]]) – The channel’s permission overwrites
parent_id (str) – The id of the parent category for a channel (each parent category can contain up to 50 channels)
nsfw (bool) – Whether the channel is nsfw
rtc_region (str) – The id of the voice region
video_quality_mode (int) – The camera video quality mode of the voice channel, 1 when not present
default_auto_archive_duration (int) – The default duration for newly created threads, in minutes, to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080
default_reaction_emoji (PartialEmoji) – The default auto-emoji for newly created threads, custom guild emojis must be enabled
available_tags (List[Dict[str, Any]]) – The channel tags used for public guilds
default_sort_order (int) – The default sorting order for posts in a forum channel
- Return type:
- async edit_channel_position(channel_id: str, *, position: int, lock_permissions: bool = False, parent_id: Optional[str] = None)[source]#
Changes the position of the channel. Only available for guild channels.
- Parameters:
channel_id (
str
) – The id of the channel to move.position (
int
) – The new position of the channel.lock_permissions – Whether to sync the permissions of the channel with the parent category.
parent_id (Optional[
str
]) – The id of the parent category to move the channel to. If not provided, the channel will be moved to the root.
- class discohook.Guild(data: Dict[str, Any], client: Client)[source]#
Bases:
PartialGuild
Represents a Discord guild. Subclass of
PartialGuild
.- id#
The id of the guild.
- Type:
str
- name#
The name of the guild.
- Type:
str
- icon#
The icon hash of the guild.
- Type:
Optional[
str
]
- icon_hash#
The icon hash of the guild.
- Type:
Optional[
str
]
- splash#
The splash hash of the guild.
- Type:
Optional[
str
]
- discovery_splash#
The discovery splash hash of the guild.
- Type:
Optional[
str
]
- owner#
Whether the user is the owner of the guild.
- Type:
Optional[
bool
]
- owner_id#
The id of the owner of the guild.
- Type:
str
- permissions#
The total permissions of the user in the guild (does not include channel overrides).
- Type:
Optional[
int
]
- afk_channel_id#
The id of the afk channel.
- Type:
Optional[
str
]
- afk_timeout#
The afk timeout in seconds.
- Type:
int
- widget_enabled#
Whether the widget is enabled.
- Type:
Optional[
bool
]
- widget_channel_id#
The id of the channel for the widget.
- Type:
Optional[
str
]
- verification_level#
The verification level required for the guild.
- Type:
int
- default_message_notifications#
The default message notifications level.
- Type:
int
- explicit_content_filter#
The explicit content filter level.
- Type:
int
- emojis#
The emojis in the guild.
- Type:
List[
Emoji
]
- features#
The features of the guild.
- Type:
List[
str
]
- mfa_level#
The mfa level required for the guild.
- Type:
int
- application_id#
The application id of the guild creator if it is bot-created.
- Type:
Optional[
str
]
- system_channel_id#
The id of the system channel.
- Type:
Optional[
str
]
- system_channel_flags#
The system channel flags.
- Type:
int
- rules_channel_id#
The id of the rules channel.
- Type:
Optional[
str
]
- max_presences#
The maximum number of presences for the guild.
- Type:
Optional[
int
]
- max_members#
The maximum number of members for the guild.
- Type:
int
- vanity_url_code#
The vanity url code of the guild.
- Type:
Optional[
str
]
- description#
The description of the guild.
- Type:
Optional[
str
]
- banner#
The banner hash of the guild.
- Type:
Optional[
str
]
The premium tier of the guild.
- Type:
int
The number of boosts of the guild.
- Type:
int
- preferred_locale#
The preferred locale of the guild.
- Type:
str
- public_updates_channel_id#
The id of the public updates channel.
- Type:
Optional[
str
]
- max_video_channel_users#
The maximum number of users in a video channel.
- Type:
Optional[
int
]
- approximate_member_count#
The approximate number of members in the guild.
- Type:
Optional[
int
]
- approximate_presence_count#
The approximate number of presences in the guild.
- Type:
Optional[
int
]
- welcome_screen#
The welcome screen object of the guild.
- Type:
Optional[
dict
]
- nsfw_level#
The nsfw level of the guild.
- Type:
int
- stickers#
The stickers in the guild.
- Type:
List[
Sticker
]
Whether the premium progress bar is enabled.
- Type:
Optional[
bool
]
- class discohook.PartialChannel(data, client: Client)[source]#
Bases:
object
Represents a partial discord channel object.
- Parameters:
data (
dict
) – The partial channel data which must contain the id.client (
Client
) – The client that the channel belongs to.
- async edit(*, name: Optional[str] = None, type: Optional[ChannelType] = None, position: Optional[int] = None, topic: Optional[str] = None, nsfw: Optional[bool] = None, rate_limit_per_user: Optional[int] = None, bitrate: Optional[int] = None, user_limit: Optional[int] = None, permission_overwrites: Optional[List[Dict[str, Any]]] = None, parent_id: Optional[str] = None, rtc_region: Optional[str] = None, video_quality_mode: Optional[int] = None, default_auto_archive_duration: Optional[int] = None, flags: Optional[int] = None, available_tags: Optional[List[Dict[str, Any]]] = None, icon: Optional[str] = None, default_reaction_emoji: Optional[PartialEmoji] = None, default_thread_rate_limit_per_user: Optional[int] = None, default_sort_order: Optional[int] = None, default_forum_layout: Optional[int] = None) Channel [source]#
Edits all kinds of channels.
- Parameters:
name (Optional[
str
]) – The new name of the channel.type (Optional[
ChannelType
]) – The new type of the channel.position (Optional[
int
]) – The new position of the channel.topic (Optional[
str
]) – The new topic of the channel.nsfw (Optional[
bool
]) – Whether the channel should be marked as nsfw.rate_limit_per_user (Optional[
int
]) – The duration of the slowmode in seconds. Must be between 0 and 21600. Applies to text and forum channels.bitrate (Optional[
int
]) – The new bitrate of the channel. Must be between 8000 and 96000. Applies to voice channels.user_limit (Optional[
int
]) – The new user limit of the channel. Must be between 0 and 99. Applies to voice channels.permission_overwrites (Optional[List[
dict
]]) – A list of permission overwrites to apply to the channel. Applies to all channel types.parent_id (Optional[
str
]) – The id of the parent category to move the channel to. Applies to all channel types.rtc_region (Optional[
str
]) – The new region of the channel. Applies to voice channels.video_quality_mode (Optional[
int
]) – The new video quality mode of the channel. Applies to voice channels.default_auto_archive_duration (Optional[
int
]) – The new default auto archive duration of the channel. Applies to text and forum channels.flags (Optional[
int
]) – The new flags of the channel. Applies to all channel types.available_tags (Optional[List[
dict
]]) – The new available tags of the channel. Applies to text and forum channels.icon (Optional[
str
]) – The new icon of the channel. Applies to Group DMs. Must be a base64 encoded string.default_reaction_emoji (Optional[
PartialEmoji
]) – The new default reaction emoji of the channel. Applies to text and forum channels.default_thread_rate_limit_per_user (Optional[
int
]) – The new default thread rate limit per user of the channel. Applies to text and forum channels.default_sort_order (Optional[
int
]) – The new default sort order of the channel. Applies to text and forum channels.default_forum_layout (Optional[
int
]) – The new default forum layout of the channel. Applies to text and forum channels.
- Returns:
The edited channel.
- Return type:
- property mention: str#
Returns the channel-mentionable string.
- Return type:
str
- async send(content: Optional[str] = None, *, embed: Optional[Embed] = None, embeds: Optional[List[Embed]] = None, view: Optional[View] = None, tts: Optional[bool] = False, file: Optional[File] = None, files: Optional[List[File]] = None)[source]#
Sends a message to the channel.
- Parameters:
content (Optional[
str
]) – The content of the message.embed (Optional[
Embed
]) – The embed to send with the message.embeds (Optional[List[
Embed
]]) – A list of embeds to send with the message.view (Optional[
View
]) – The view to send with the message.tts (Optional[
bool
]) – Whether the message should be sent with text-to-speech.file (Optional[File]) – A file to send with the message.
files (Optional[List[File]]) – A list of files to send with the message.
- class discohook.Channel(data: dict, client: Client)[source]#
Bases:
PartialChannel
Represents a discord channel object.
- id#
The id of the channel.
- Type:
str
- type#
The type of the channel.
- Type:
Optional[
int
]
- guild_id#
The id of the guild the channel belongs to.
- Type:
Optional[
str
]
- position#
The position of the channel.
- Type:
Optional[
int
]
- permission_overwrites#
A list of permission overwrites for the channel.
- Type:
Optional[List[
dict
]]
- name#
The name of the channel.
- Type:
Optional[
str
]
- topic#
The topic of the channel.
- Type:
Optional[
str
]
- nsfw#
Whether the channel is nsfw.
- Type:
Optional[
bool
]
- last_message_id#
The id of the last message sent in the channel.
- Type:
Optional[
str
]
- bitrate#
The bitrate of the channel if it is a voice channel.
- Type:
Optional[
int
]
- user_limit#
The user limit of the channel if it is a voice channel.
- Type:
Optional[
int
]
- rate_limit_per_user#
The rate limit per user of the channel if it is a text channel.
- Type:
Optional[
int
]
- recipients#
A list of recipients of the channel if it is a dm channel.
- Type:
Optional[List[
dict
]]
- icon#
The icon of the channel if it is a dm channel.
- Type:
Optional[
str
]
- owner_id#
The id of the owner of the channel if it is a dm channel.
- Type:
Optional[
str
]
- application_id#
The id of the application of the channel if it is a group dm channel.
- Type:
Optional[
str
]
- parent_id#
The id of the parent category of the channel.
- Type:
Optional[
str
]
- last_pin_timestamp#
The timestamp of the last pinned message in the channel.
- Type:
Optional[
str
]
- rtc_region#
The rtc region of the channel.
- Type:
Optional[
str
]
- video_quality_mode#
The video quality mode of the channel.
- Type:
Optional[
int
]
- message_count#
The message count of the channel.
- Type:
Optional[
int
]
- member_count#
The member count of the channel.
- Type:
Optional[
int
]
- thread_metadata#
The thread metadata of the channel.
- Type:
Optional[
dict
]
- member#
The member of the channel.Appears in thread channels.
- Type:
Optional[
dict
]
- default_auto_archive_duration#
The default auto archive duration of the channel.Appears in thread channels.
- Type:
Optional[
int
]
- permissions#
The permissions of the channel.
- Type:
Optional[
str
]
- flags#
The flags of the channel.
- Type:
Optional[
int
]
- total_message_sent#
The total message sent of the channel.
- Type:
Optional[
int
]
- available_tags#
A list of available tags of the channel.Appears in thread channels.
- Type:
Optional[List[
str
]]
- default_reaction_emoji#
The default reaction emoji of the channel.Appears in thread channels.
- Type:
Optional[
dict
]
- default_thread_rate_limit_per_user#
The default rate limit per user of the channel.Appears in thread channels.
- Type:
Optional[
int
]
- default_sort_order#
The default sort order of the channel.Appears in forum channels.
- Type:
Optional[
int
]
- default_forum_layout#
The default channel layout of the channel.Appears in forum channels.
- Type:
Optional[
int
]
- class discohook.PartialRole(data: Dict[str, Any], client: Client)[source]#
Bases:
object
- async edit(*, name: Optional[str] = None, permissions: Optional[List[Permissions]] = None, color: Optional[int] = None, hoist: Optional[bool] = None, mentionable: Optional[bool] = None, description: Optional[str] = None, unicode_emoji: Optional[str] = None, icon_data_uri: Optional[str] = None) Role [source]#
Edits the role.
- Parameters:
name (Optional[
str
]) – The name of the role.permissions (Optional[
Permissions
]) – The permissions of the role.color (Optional[
int
]) – The color of the role.hoist (Optional[
bool
]) – Whether the role has separability in the member list.mentionable (Optional[
bool
]) – Whether the role is mentionable.description (Optional[
str
]) – The description of the role.unicode_emoji (Optional[
str
]) – The unicode emoji of the role.icon_data_uri (Optional[
str
]) – The icon of the role. Must be a data URI (base64 encoded).
- Return type:
- async edit_position(role_id: str, *, position: int) List[Role] [source]#
Changes the position of the role. :param role_id: The id of the role to move. :type role_id:
str
:param position: The new position of the role. :type position:int
- Return type:
- property mention: str#
Returns a string that allows you to mention the role.
- Return type:
str
- class discohook.Role(data: dict, client: Client)[source]#
Bases:
PartialRole
Represents a discord Role.
- id#
The unique ID of the role.
- Type:
str
- name#
The name of the role.
- Type:
str
- color#
The color of the role.
- Type:
int
- hoist#
Whether the role has separability in the member list.
- Type:
bool
- position#
The position of the role.
- Type:
int
- permissions#
The permissions of the role.
- Type:
str
- managed#
Whether the role is managed by an integration.
- Type:
bool
- mentionable#
Whether the role is mentionable.
- Type:
bool
- description#
The description of the role.
- Type:
Optional[
str
]
- unicode_emoji#
The unicode emoji of the role.
- Type:
Optional[
str
]
- icon#
The icon of the role.
- Type:
Optional[
str
]
- flags#
The flags of the role.
- Type:
int
- has_permission(permissions: Permissions) bool [source]#
Checks if the role has the given permissions.
- Parameters:
permissions (
Permissions
) – The permissions to check.- Return type:
bool
- class discohook.ApplicationCommand(name: str, description: Optional[str] = None, options: Optional[List[Option]] = None, dm_access: bool = True, permissions: Optional[List[Permissions]] = None, category: ApplicationCommandType = ApplicationCommandType.slash)[source]#
Bases:
object
A class representing a discord application command.
- Parameters:
name (str) – The name of the command.
description (str | None) – The description of the command. Does not apply to user & message commands.
options (List[Option] | None) – The options of the command. Does not apply to user & message commands.
dm_access (bool) – Whether the command can be used in DMs. Defaults to True.
permissions (List[Permissions] | None) – The default permissions of the command.
category (ApplicationCommandType) – The category of the command. Defaults to slash commands.
- autocomplete(name: str)[source]#
A decorator to register a callback for the command’s autocomplete options.
- Parameters:
name (str) – The name of the option to register the autocomplete for.
- on_interaction(coro: Callable)[source]#
A decorator to register a callback for the command.
- Parameters:
coro (Callable) – The callback to register.
- subcommand(name: str, description: str, *, options: Optional[List[Option]] = None)[source]#
A decorator to register a subcommand for the command.
- Parameters:
name (str) – The name of the subcommand.
description (str) – The description of the subcommand.
options (Optional[List[Option]]) – The options of the subcommand.
- Returns:
The subcommand object.
- Return type:
- Raises:
TypeError – If the callback is not a coroutine.
- class discohook.SubCommand(name: str, description: str, options: Optional[List[Option]] = None, *, callback: Optional[Callable] = None)[source]#
Bases:
object
A class representing a discord application command subcommand.
- Parameters:
name (str) – The name of the subcommand.
description (str) – The description of the subcommand.
options (List[Option] | None) – The options of the subcommand.
callback (Callable | None) – The callback of the subcommand.
- class discohook.Embed(title: Optional[str] = None, *, description: Optional[str] = None, url: Optional[str] = None, color: Optional[int] = None, timestamp: Optional[str] = None)[source]#
Bases:
object
Represents a discord Embed object.
- Parameters:
title (str | None) – The title of the embed.
description (str | None) – The description of the embed.
url (str | None) – The url of the embed.
color (int | None) – The color of the embed.
timestamp (str | None) – The timestamp of the embed.
- add_field(name: str, value: str, *, inline: bool = False)[source]#
Adds a field to the embed.
- Parameters:
name (
str
) – The name of the field.value (
str
) – The value of the field.inline (
bool
) – Whether the field is inline.
- author(*, name: str, url: Optional[str] = None, icon_url: Optional[str] = None)[source]#
Sets the author of the embed.
- Parameters:
name (
str
) – The name of the author.url (Optional[
str
]) – The url of the author.icon_url (Optional[
str
]) – The icon url of the author.
Sets the footer of the embed.
- Parameters:
text (
str
) – The text of the footer.icon_url (Optional[
str
]) – The icon url of the footer.
- image_from_attachment(name: str)[source]#
Sets the image of the embed from a file attachment.
- Parameters:
name (
str
) – name of the file attachment.
- thumbnail(url: str)[source]#
Sets the thumbnail of the embed.
- Parameters:
url (
str
) – The url of the thumbnail.
- class discohook.File(name: str, *, content: BytesIO, description: Optional[str] = None, spoiler: bool = False)[source]#
Bases:
object
Represents a file to send to Discord.
- Parameters:
name (str) – The name of the file.
content (io.BytesIO) – The content of the file.
description (str | None) – The description of the file.
spoiler (bool) – Whether the file is a spoiler.
- class discohook.PartialEmoji(name: str, id: Optional[str] = None, animated: bool = False)[source]#
Bases:
object
Represents a discord PartialEmoji object.
- Parameters:
name (
str
) – The name of the emoji.id (
str
) – The unique id of the emoji.animated (
bool
) – Whether the emoji is animated.
- class discohook.TextInputFieldLength(value)[source]#
Bases:
Enum
The length of a text input field for a modal.
- short#
Used to specify a short length text input field (up to 100 characters).
- Type:
int
- long#
Used to specify a long length text input field (up to 3000 characters).
- Type:
int
- class discohook.ApplicationCommandType(value)[source]#
Bases:
Enum
The type of application command.
- slash#
Used to specify a slash command.
- Type:
int
- user#
Used to specify a user command.
- Type:
int
- message#
Used to specify a message command.
- Type:
int
- class discohook.ChannelType(value)[source]#
Bases:
Enum
Use to specify discord channel type in application command Option.
- guild_text#
Used to specify a guild text channel.
- Type:
int
- dm#
Used to specify a dm channel.
- Type:
int
- guild_voice#
Used to specify a guild voice channel.
- Type:
int
- group_dm#
Used to specify a group dm channel.
- Type:
int
- guild_category#
Used to specify a guild category channel.
- Type:
int
- guild_news#
Used to specify a guild news channel.
- Type:
int
- guild_store#
Used to specify a guild store channel.
- Type:
int
- guild_news_thread#
Used to specify a guild news thread channel.
- Type:
int
- guild_public_thread#
Used to specify a guild public thread channel.
- Type:
int
- guild_private_thread#
Used to specify a guild private thread channel.
- Type:
int
- guild_stage_voice#
Used to specify a guild stage voice channel.
- Type:
int
- class discohook.ButtonStyle(value)[source]#
Bases:
Enum
Represents the style of a button.
- blurple#
Used to specify a blurple button.
- Type:
int
- grey#
Used to specify a grey button.
- Type:
int
- green#
Used to specify a green button.
- Type:
int
- red#
Used to specify a red button.
- Type:
int
- link#
Used to specify a link type button.
- Type:
int
- class discohook.Interaction(data: Dict[str, Any], client: Client)[source]#
Bases:
object
Base interaction class for all interactions
Properties#
- id: str
The unique id of the interaction
- type: int
The type of the interaction
- token: str
The token of the interaction
- version: int
The version of the interaction
- application_id: str
The id of the application that the interaction was triggered for
- data: Optional[Dict[str, Any]]
The command data payload (if the interaction is a command)
- guild_id: Optional[str]
The guild id of the interaction
- channel_id: Optional[str]
The channel id of the interaction
- app_permissions: Optional[int]
The permissions of the application
- locale: Optional[str]
The locale of the interaction
- guild_locale: Optional[str]
The guild locale of the interaction
- param data:
The interaction data payload
- type data:
Dict[str, Any]
- param client:
The request object from fastapi
- type client:
Client
- property app_permissions: Optional[int]#
The permissions of the application
- Return type:
Optional[int]
- property application_id: str#
The id of the application that the interaction was triggered for
- Return type:
str
- property author: Optional[Union[User, Member]]#
The author of the interaction
If the interaction was triggered in a guild, this will return a member object else it will return user object.
- async autocomplete(choices: List[Choice])[source]#
Sends autocomplete choices to the interaction (max 25)
- Parameters:
choices (List[Choice]) – The choices to send
- property channel: PartialChannel#
The channel where the interaction was triggered
- Return type:
- property channel_id: str#
The channel id of the interaction
- Return type:
Optional[str]
- async defer(ephemeral: bool = False) InteractionResponse [source]#
Defers the interaction
- Parameters:
ephemeral (bool) – Whether the successive responses should be ephemeral or not (only for Application Commands)
- async followup(content: Optional[str] = None, *, embed: Optional[Embed] = None, embeds: Optional[List[Embed]] = None, view: Optional[View] = None, tts: Optional[bool] = False, file: Optional[File] = None, files: Optional[List[File]] = None, ephemeral: Optional[bool] = False, suppress_embeds: Optional[bool] = False) FollowupResponse [source]#
Sends a follow-up message to a deferred interaction
- Parameters:
content (Optional[str]) – The content of the message to send
embed (Optional[Embed]) – The embed to send with the message
embeds (Optional[List[Embed]]) – The list of embeds to send with the message (max 10)
view (Optional[View]) – The view to send with the message
tts (Optional[bool]) – Whether the message should be sent as tts or not
file (Optional[File]) – The file to send with the message
files (Optional[List[File]]) – The list of files to send with the message
ephemeral (Optional[bool]) – Whether the message should be ephemeral or not
suppress_embeds (Optional[bool]) – Whether the message should suppress embeds or not
- property from_originator: bool#
Whether the interaction was triggered by the same user who triggered the message
- Return type:
bool
- property guild_id: Optional[str]#
The guild id of the interaction
- Return type:
Optional[str]
- property guild_locale: Optional[str]#
The guild locale of the interaction
- Return type:
Optional[str]
- property id: str#
The unique id of the interaction
- Return type:
str
- property locale: Optional[str]#
The locale of the interaction
- Return type:
Optional[str]
- property message: Optional[Message]#
The message from which the component interaction was triggered
- Return type:
- async original_response() Optional[Message] [source]#
Gets the original response message of the interaction if the interaction has been responded to.
- Returns:
The original response message
- Return type:
- property responded: bool#
Whether the interaction has been responded to
- Return type:
bool
- async response(content: Optional[str] = None, *, embed: Optional[Embed] = None, embeds: Optional[List[Embed]] = None, view: Optional[View] = None, tts: Optional[bool] = False, file: Optional[File] = None, files: Optional[List[File]] = None, ephemeral: Optional[bool] = False, suppress_embeds: Optional[bool] = False) InteractionResponse [source]#
Sends a response to the interaction
- Parameters:
content (Optional[str]) – The content of the message to send
embed (Optional[Embed]) – The embed to send with the message
embeds (Optional[List[Embed]]) – The list of embeds to send with the message (max 10)
view (Optional[View]) – The view to send with the message
tts (Optional[bool]) – Whether the message should be sent as tts or not
file (Optional[File]) – The file to send with the message
files (Optional[List[File]]) – The list of files to send with the message
ephemeral (Optional[bool]) – Whether the message should be ephemeral or not
suppress_embeds (Optional[bool]) – Whether the embeds should be suppressed or not
- Return type:
- async send_modal(modal: Union[Modal, Any])[source]#
Sends a modal to the interaction
- Parameters:
modal (Modal) – The modal to send
- property token: str#
The token of the interaction
- Return type:
str
- property type: Optional[InteractionType]#
The type of the interaction
- Return type:
Optional[InteractionType]
- async update_message(content: Optional[str] = typing.Any, *, embed: Optional[Embed] = typing.Any, embeds: Optional[List[Embed]] = typing.Any, view: Optional[View] = typing.Any, tts: Optional[bool] = typing.Any, file: Optional[File] = typing.Any, files: Optional[List[File]] = typing.Any, suppress_embeds: Optional[bool] = typing.Any) None [source]#
Edits the message, the component was attached to
- Parameters:
content (Optional[str]) – The new content of the message.
embed (Optional[Embed]) – The new embed of the message.
embeds (Optional[List[Embed]]) – The new embeds of the message.
view (Optional[View]) – The new view of the message.
tts (Optional[bool]) – Whether the message should be sent with text-to-speech.
file (Optional[File]) – A file to send with the message.
files (Optional[List[File]]) – A list of files to send with the message.
suppress_embeds (Optional[bool]) – Whether the embeds should be suppressed.
- property version: int#
The version of the interaction
- Return type:
int
- class discohook.Message(payload: Dict[str, Any], client: Client)[source]#
Bases:
object
Represents a Discord message.
Properties#
- id:
str
The id of the message.
- channel_id:
str
The id of the channel the message was sent in.
- author:
User
The author of the message.
- content:
str
The content of the message.
- timestamp:
str
The timestamp of the message.
- edited_timestamp: Optional[
str
] The timestamp of when the message was last edited.
- tts:
bool
Whether the message was sent using text-to-speech.
- mention_everyone:
bool
Whether the message mentions everyone.
- mentions: List[
User
] The users mentioned in the message.
- mention_roles: List[
Role
] The roles mentioned in the message.
- mention_channels: Optional[
dict
] The channels mentioned in the message.
- attachments:
dict
The attachments in the message.
- embeds:
list
The embeds in the message.
- reactions: Optional[
list
] The reactions in the message. …
- async edit(content: Optional[str] = typing.Any, *, embed: Optional[Embed] = typing.Any, embeds: Optional[List[Embed]] = typing.Any, view: Optional[View] = typing.Any, tts: Optional[bool] = typing.Any, file: Optional[File] = typing.Any, files: Optional[List[File]] = typing.Any, suppress_embeds: Optional[bool] = typing.Any)[source]#
Edits the message.
- Parameters:
content (Optional[str]) – The new content of the message.
embed (Optional[Embed]) – The new embed of the message.
embeds (Optional[List[Embed]]) – The new embeds of the message.
view (Optional[View]) – The new view of the message.
tts (Optional[bool]) – Whether the message should be sent with text-to-speech.
file (Optional[File]) – A file to send with the message.
files (Optional[List[File]]) – A list of files to send with the message.
suppress_embeds (Optional[bool]) – Whether the embeds should be suppressed.
- id:
- class discohook.FollowupResponse(payload: Dict[str, Any], interaction: Interaction)[source]#
Bases:
object
Represents a followup message sent by an interaction, subclassed from
Message
.- async edit(content: Optional[str] = typing.Any, *, embed: Optional[Embed] = typing.Any, embeds: Optional[List[Embed]] = typing.Any, view: Optional[View] = typing.Any, tts: Optional[bool] = typing.Any, file: Optional[File] = typing.Any, files: Optional[List[File]] = typing.Any, suppress_embeds: Optional[bool] = typing.Any) Message [source]#
Edits the followup message.
:param same as
Message.edit()
:
- class discohook.InteractionResponse(interaction: Interaction)[source]#
Bases:
object
Represents a response message sent by an interaction
- async edit(content: Optional[str] = typing.Any, *, embed: Optional[Embed] = typing.Any, embeds: Optional[List[Embed]] = typing.Any, view: Optional[View] = typing.Any, tts: Optional[bool] = typing.Any, file: Optional[File] = typing.Any, files: Optional[List[File]] = typing.Any, suppress_embeds: Optional[bool] = typing.Any) Message [source]#
Edits the response message.
:param same as
Message.edit()
:
- class discohook.Modal(title: str, *, custom_id: Optional[str] = None)[source]#
Bases:
Component
A modal for discord.
- Parameters:
title (
str
) – The title of the modal.custom_id (
str
) – The unique id of the modal.
- add_field(label: str, field_id: str, *, required: bool = False, hint: Optional[str] = None, default_text: Optional[str] = None, min_length: int = 0, max_length: int = 4000, style: TextInputFieldLength = TextInputFieldLength.short)[source]#
Add a text input field to the modal.
- Parameters:
label (str) – The label of the field.
field_id (str) – A unique id of the text input field. Must be valid python identifier.
required (bool) – Whether the field is required or not.
hint (str) – The hint to be displayed on the field.
default_text (str) – The default text to be displayed on the field.
min_length (int) – The minimum length of the field.
max_length (int) – The maximum length of the field.
style (TextInputFieldLength) – The style of the field.
- class discohook.StringOption(name: str, description: str, *, required: Optional[bool] = False, max_length: Optional[int] = 100, min_length: Optional[int] = 1, choices: Optional[List[Choice]] = None, autocomplete: Optional[bool] = False)[source]#
Bases:
Option
Represents a string type option for an application command, subclassed from Option
- Parameters:
name (str) – The name of the option.
description (str) – The description of the option.
required (bool) – Whether the option is required or not.
max_length (int) – The maximum length of the string.
min_length (int) – The minimum length of the string.
choices (List[Choice]) – The choices for the string.
autocomplete (bool) – Whether the string should be auto completed or not.
- class discohook.IntegerOption(name: str, description: str, *, required: Optional[bool] = False, max_value: Optional[int] = None, min_value: Optional[int] = None, choices: Optional[List[Choice]] = None, autocomplete: Optional[bool] = False)[source]#
Bases:
Option
Represents an integer type option for an application command, subclassed from Option
- Parameters:
name (str) – The name of the option.
description (str) – The description of the option.
required (bool) – Whether the option is required or not.
max_value (int) – The maximum value of the integer.
min_value (int) – The minimum value of the integer.
choices (List[Choice]) – The choices for the integer.
autocomplete (bool) – Whether the integer should be auto completed or not.
- class discohook.BooleanOption(name: str, description: str, *, required: Optional[bool] = False)[source]#
Bases:
Option
Represents a boolean type option for an application command, subclassed from Option
- class discohook.UserOption(name: str, description: str, *, required: Optional[bool] = False)[source]#
Bases:
Option
Represents a user type option for an application command, subclassed from Option
- class discohook.ChannelOption(name: str, description: str, *, required: Optional[bool] = False, channel_types: Optional[List[ChannelType]] = None)[source]#
Bases:
Option
Represents a channel type option for an application command, subclassed from Option
- Parameters:
name (str) – The name of the option.
description (str) – The description of the option.
required (bool) – Whether the option is required or not.
channel_types (List[ChannelType]) – The channel types that are allowed for this option.
- class discohook.RoleOption(name: str, description: str, *, required: Optional[bool] = False)[source]#
Bases:
Option
Represents a role type option for an application command, subclassed from Option
- class discohook.MentionableOption(name: str, description: str, *, required: Optional[bool] = False)[source]#
Bases:
Option
Represents a mentionable type option for an application command, subclassed from Option
- Parameters:
name (str) – The name of the option.
description (str) – The description of the option.
required (bool) – Whether the option is required or not.
- class discohook.NumberOption(name: str, description: str, *, required: Optional[bool] = False, max_value: Optional[float] = None, min_value: Optional[float] = None, choices: Optional[List[Choice]] = None, autocomplete: Optional[bool] = False)[source]#
Bases:
Option
Represents a number type option for an application command, subclassed from Option
- Parameters:
name (str) – The name of the option.
description (str) – The description of the option.
required (bool) – Whether the option is required or not.
max_value (float) – The maximum value of the number.
min_value (float) – The minimum value of the number.
choices (List[Choice]) – The choices for the number.
autocomplete (bool) – Whether the number should be auto completed or not.
- class discohook.SelectOption(label: str, value: str, *, description: Optional[str] = None, emoji: Optional[PartialEmoji] = None, default: bool = False)[source]#
Bases:
object
Represents a discord select menu option object.
- Parameters:
label (
str
) – The text to be displayed on the option.value (
str
) – The value to be sent to the bot when the option is selected.description (str | None) – The description to be displayed on the option.
emoji (
str
|PartialEmoji
| None) – The emoji to be displayed on the option.default (
bool
) – Whether the option is selected by default or not.
- class discohook.Select(options: Optional[List[SelectOption]] = None, *, placeholder: Optional[str] = None, min_values: Optional[int] = None, max_values: Optional[int] = None, channel_types: Optional[List[ChannelType]] = None, type: Union[MessageComponentType, SelectType] = MessageComponentType.text_select, disabled: Optional[bool] = False, custom_id: Optional[str] = None)[source]#
Bases:
Component
Represents a discord select menu component.
- Parameters:
options (Optional[List[
SelectOption
]]) – The options to be displayed on the select menu.channel_types (Optional[List[
ChannelType
]]) – The channel types to be displayed on the select menu if the type is set toSelectMenuType.channel
.placeholder (Optional[
str
]) – The placeholder to be displayed on the select menu.min_values (Optional[
int
]) – The minimum number of options that can be selected.max_values (Optional[
int
]) – The maximum number of options that can be selected.disabled (Optional[
bool
]) – Whether the select menu is disabled or not.type (
SelectType
) – The type of the select menu.
- class discohook.Button(label: Optional[str] = None, *, url: Optional[str] = None, style: ButtonStyle = ButtonStyle.blurple, disabled: bool = False, emoji: Optional[Union[str, PartialEmoji]] = None, custom_id: Optional[str] = None)[source]#
Bases:
Component
Represents a discord button type component.
- Parameters:
label (str | None) – The text to be displayed on the button.
url (str | None) – The url to be opened when the button is clicked if the style is set to
ButtonStyle.link
.style (
ButtonStyle
) – The style of the button.disabled (
bool
) – Whether the button is disabled or not.emoji (
str
|PartialEmoji
| None) – The emoji to be displayed on the button.
- class discohook.View[source]#
Bases:
object
Represents a discord message component tree.
This is used to create actions rows and add buttons and select menus to them without having tree conflicts.
- components#
The list of components to be sent to discord. Do not modify this directly.
- Type:
List[
dict
]
- children#
The list of children to be sent to discord. Do not modify this directly.