Discord HTTP Interaction API Wrapper#
A simple wrapper for the Discord HTTP Interaction API, designed for serverless apps.
- copyright
2022-present Sougata Jana
- license
MIT, see LICENSE for more details.
- class discohook.AllowedMentions(parse: Optional[List[discohook.enums.AllowedMentionsType]] = None, roles: Optional[List[str]] = None, users: Optional[List[str]] = None, replied_user: Optional[bool] = None)[source]#
Bases:
objectRepresents a discord allowed mentions object.
- Parameters
parse (List[AllowedMentionsType] | None) – The types of mentions to parse from the message content.
roles (List[str] | None) – The roles to mention.
users (List[str] | None) – The users to mention.
replied_user (bool | None) – Whether to mention the user the message is replying to.
- class discohook.AllowedMentionsType(value)[source]#
Bases:
str,enum.EnumThe type of mentions allowed in a message.
Used internally by the library. You should not need to use this.
- everyone = 'everyone'#
- roles = 'roles'#
- users = 'users'#
- class discohook.ApplicationCommand(name: str, *, description: Optional[str] = None, options: Optional[List[discohook.option.Option]] = None, nsfw: bool = False, integration_types: Optional[List[discohook.enums.ApplicationIntegrationType]] = None, contexts: Optional[List[discohook.enums.InteractionContextType]] = None, permissions: Optional[List[discohook.permission.Permission]] = None, type: discohook.enums.ApplicationCommandType = ApplicationCommandType.slash, guild_id: Optional[str] = None, callback: Callable[[Interaction, Any], Coroutine[[Any, Any], Any]])[source]#
Bases:
discohook.component.InteractableA 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.
nsfw (bool) – Whether the command is age restricted. Defaults to False.
permissions (List[Permission] | None) – The default permissions of the command.
type (ApplicationCommandType) – The category of the command. Defaults to slash commands.
integration_types (List[ApplicationIntegrationType] | None) – Installation context(s) where the command is available. only for globally-scoped commands.
contexts (List[InteractionContextType] | None) – Interaction context(s) where the command can be used, only for globally-scoped commands.
- on_autocomplete(coro: Callable[[Interaction, Any], Coroutine[[Any, Any], Any]])[source]#
A decorator to register a callback for the command’s autocomplete options.
- subcommand(name: Optional[str] = None, description: Optional[str] = None, *, options: Optional[List[discohook.option.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.ApplicationCommandOptionType(value)[source]#
Bases:
int,enum.EnumThe type of application command option.
Used internally by the library. You should not need to use this.
- attachment = 11#
- boolean = 5#
- channel = 7#
- integer = 4#
- mentionable = 9#
- number = 10#
- role = 8#
- string = 3#
- subcommand = 1#
- subcommand_groups = 2#
- user = 6#
- class discohook.ApplicationCommandType(value)[source]#
Bases:
int,enum.EnumThe 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
- message = 3#
- slash = 1#
- user = 2#
- class discohook.ApplicationIntegrationType(value)[source]#
Bases:
int,enum.EnumInstallation context(s) where the command is available.
- guild = 0#
- user = 1#
- class discohook.Button(label: Optional[str] = None, *, url: Optional[str] = None, style: discohook.enums.ButtonStyle = ButtonStyle.blurple, disabled: bool = False, emoji: Optional[Union[str, discohook.emoji.PartialEmoji]] = None, custom_id: Optional[str] = None)[source]#
Bases:
discohook.component.ComponentRepresents 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.ButtonStyle(value)[source]#
Bases:
int,enum.EnumRepresents 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
- blurple = 1#
- green = 3#
- grey = 2#
- link = 5#
- red = 4#
- class discohook.Channel(client: Client, data: dict)[source]#
Bases:
discohook.channel.PartialChannelRepresents 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.ChannelType(value)[source]#
Bases:
int,enum.EnumUse 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_announcement#
Used to specify a guild announcement channel.
- Type
int
- guild_announcement_thread#
Used to specify a guild announcement thread channel.
- Type
int
- public_thread#
Used to specify a guild public thread channel.
- Type
int
- 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
- guild_directory#
Used to specify a guild directory channel.
- Type
int
- guild_forum#
Used to specify a guild forum channel.
- Type
int
- guild_media#
Used to specify a guild media channel.
- Type
int
- dm = 1#
- group_dm = 3#
- guild_announcement = 5#
- guild_announcement_thread = 10#
- guild_category = 4#
- guild_directory = 14#
- guild_forum = 15#
- guild_media = 16#
- guild_stage_voice = 13#
- guild_text = 0#
- guild_voice = 2#
- private_thread = 12#
- public_thread = 11#
- class discohook.Client(*, application_id: Union[int, str], public_key: str, token: str, route: str = '/interactions', password: Optional[str] = None, default_help_command: bool = False, **kwargs)[source]#
Bases:
starlette.applications.StarletteThe 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.
password (str | None) – The password to use for the dashboard.
default_help_command (bool) – Whether to use the default help command or not. Defaults to False.
**kwargs – Keyword arguments to pass to the FastAPI instance.
- add_commands(*commands: Union[discohook.command.ApplicationCommand, Any])[source]#
Add commands to the client.
- Parameters
*commands (ApplicationCommand) – The commands to add to the client.
- async create_application_emoji(name: str, image_base64: str)[source]#
Create a new emoji in a guild.
- Parameters
name (str) – The name of the emoji.
image_base64 (str) – The base64 encoded image of the emoji. ( Size must be less than 256kb )
- async create_webhook(channel_id: str, *, name: str, image_base64: Optional[str] = None)[source]#
Create a webhook in a channel.
- Parameters
channel_id (str) – The ID of the channel to create the webhook in.
name – The name of the webhook.
image_base64 – The base64 encoded image of the webhook.
- Return type
- async delete_application_emoji(emoji_id: str)[source]#
Delete an existing emoji in a guild.
- Parameters
emoji_id (str) – The ID of the emoji.
- async delete_command(command_id: str, *, guild_id: Optional[str] = None)[source]#
Delete a command from the client.
- Parameters
command_id (str) – The id of the command to delete.
guild_id (str | None) – The id of the guild to delete the command from. Defaults to None.
- async edit(username: str, *, avatar: Optional[str] = None)[source]#
Edits the client user.
- Parameters
username (
str) – The new username of the client user.avatar (Optional[
str]) – The new avatar of the client user in base64 data URI scheme.
- async edit_application_emoji(emoji_id: str, name: str)[source]#
Edit an existing emoji in a guild.
- Parameters
emoji_id (str) – The ID of the emoji.
name (str) – The name of the emoji.
- async fetch_application_emoji(emoji_id: str)[source]#
Fetch an emoji from the client.
- Parameters
emoji_id (str) – The ID of the emoji to fetch.
- async fetch_channel(channel_id: str) Optional[discohook.channel.Channel][source]#
Fetches the channel of given id.
- Return type
- async fetch_commands()[source]#
Fetches the commands of the client.
- Return type
List[Dict[str, Any]]
- async fetch_guild(guild_id: str) Optional[discohook.guild.Guild][source]#
Fetches the guild of given id.
- Return type
- async fetch_info() Dict[str, Any][source]#
Returns the application object associated with the requesting client user.
- Return type
Dict[str, Any]
- async fetch_user(user_id: str) Optional[discohook.user.User][source]#
Fetches the user 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
- load(cmd: discohook.command.ApplicationCommand) discohook.command.ApplicationCommand[source]#
A decorator to load a command into the client.
- load_view(view: discohook.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.
- async me() discohook.user.User[source]#
Get the client as a discord user.
- Returns
The client as a user.
- Return type
- preload(custom_id: str)[source]#
This decorator is used to load a component into the client. This method will help you to use persistent components with static custom ids.
- Parameters
custom_id (str) – The unique custom id of the component.
- Raises
ValueError – If the custom id is not a not empty string or is not provided.
- async send(channel_id: str, content: Optional[str] = None, *, tts: bool = False, embed: Optional[discohook.embed.Embed] = None, embeds: Optional[List[discohook.embed.Embed]] = None, file: Optional[discohook.file.File] = None, files: Optional[List[discohook.file.File]] = None, view: Optional[discohook.view.View] = None, poll: Optional[discohook.poll.Poll] = None) discohook.message.Message[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.
view (Optional[View]) – The view to send with the message.
poll (Optional[Poll]) – The poll to send with the message.
- Returns
The message that was sent.
- Return type
- class discohook.ComponentType(value)[source]#
Bases:
int,enum.EnumThe type of message component.
Used internally by the library. You should not need to use this.
- action_row = 1#
- button = 2#
- select_channel = 8#
- select_mentionable = 7#
- select_role = 6#
- select_text = 3#
- select_user = 5#
- text_input = 4#
- class discohook.Embed(title: Optional[str] = None, *, description: Optional[str] = None, url: Optional[str] = None, color: Optional[Union[str, int]] = None, timestamp: Optional[str] = None)[source]#
Bases:
objectRepresents 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 | str | None) – The color of the embed in hex or int.
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.
- property attachments: List[discohook.file.File]#
Returns the attachments of the embed.
- classmethod from_dict(data: Dict[str, Any]) discohook.embed.Embed[source]#
Creates an embed from a dictionary. This method is handy when you want to create an embed manually.
- Parameters
data (
dict) – The dictionary to create the embed from.- Returns
The created embed.
- Return type
- set_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.
- set_image(img: Union[str, discohook.file.File])[source]#
Sets the image of the embed from a file attachment or url.
- Parameters
img (
str|File) – The url or file attachment of the image.
- set_thumbnail(img: Union[str, discohook.file.File])[source]#
Sets the thumbnail of the embed.
- Parameters
img (
str|File) – The url or file attachment of the thumbnail.
- class discohook.File(name: str, *, content: bytes, spoiler: bool = False, description: Optional[str] = None)[source]#
Bases:
objectRepresents a file to send to Discord.
- Parameters
name (str) – The name of the file.
content (bytes) – The content of the file in bytes.
description (str | None) – The description of the file.
spoiler (bool) – Whether the file is a spoiler.
- class discohook.FollowupResponse(payload: Dict[str, Any], interaction: Interaction)[source]#
Bases:
objectRepresents a followup message sent by an interaction, subclassed from
Message.- async edit(content: Optional[str] = typing.Any, *, embed: Optional[discohook.embed.Embed] = typing.Any, embeds: Optional[List[discohook.embed.Embed]] = typing.Any, view: Optional[discohook.view.View] = typing.Any, tts: Optional[bool] = typing.Any, file: Optional[discohook.file.File] = typing.Any, files: Optional[List[discohook.file.File]] = typing.Any, suppress_embeds: Optional[bool] = typing.Any) discohook.message.Message[source]#
Edits the followup message.
:param same as
Message.edit():
- class discohook.Guild(client: Client, data: Dict[str, Any])[source]#
Bases:
discohook.guild.PartialGuildRepresents 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.Interaction(client: Client, data: Dict[str, Any])[source]#
Bases:
objectBase interaction class for all interactions
- 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
- created_at: int
The timestamp when the interaction was created
- Parameters
data (Dict[str, Any]) – The interaction data payload
client (Client) – The stateful 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: discohook.user.User#
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.
- property channel: discohook.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]
- property context: Optional[discohook.enums.InteractionContextType]#
Context where the interaction was triggered from.
- Return type
InteractionContextType | None
- property created_at: float#
The timestamp when the interaction was created
- Return type
float
- property data: Dict[str, Any]#
The command data payload (if the interaction is a command)
- Return type
Dict[str, Any]
- property from_originator: bool#
Whether the interaction was triggered by the same user who triggered the message
- Return type
bool
- property guild: Optional[discohook.guild.PartialGuild]#
- 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[discohook.message.Message]#
The message from which the component interaction was triggered
- Return type
- async original_response() Optional[discohook.message.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 parsed_command_options: Optional[Dict[str, Any]]#
The resolved command options payload (if the interaction is a command)
- property responded: bool#
Whether the interaction has been responded to
- Return type
bool
- property response#
The response adapter for the interaction
- Return type
ResponseAdapter
- property token: str#
The token of the interaction
- Return type
str
- property type: Optional[discohook.enums.InteractionType]#
The type of the interaction
- Return type
Optional[InteractionType]
- property version: int#
The version of the interaction
- Return type
int
- class discohook.InteractionCallbackType(value)[source]#
Bases:
int,enum.EnumThe type of interaction callback.
Used internally by the library. You should not need to use this.
- autocomplete = 8#
- channel_message_with_source = 4#
- deferred_channel_message_with_source = 5#
- deferred_update_component_message = 6#
- modal = 9#
- pong = 1#
- update_component_message = 7#
- class discohook.InteractionContextType(value)[source]#
Bases:
int,enum.EnumThe type of interaction context.
- bot_dm = 1#
- guild = 0#
- private_channel = 2#
- class discohook.InteractionResponse(interaction: Interaction)[source]#
Bases:
objectRepresents a response message sent by an interaction
- async edit(content: Optional[str] = typing.Any, *, embed: Optional[discohook.embed.Embed] = typing.Any, embeds: Optional[List[discohook.embed.Embed]] = typing.Any, view: Optional[discohook.view.View] = typing.Any, tts: Optional[bool] = typing.Any, file: Optional[discohook.file.File] = typing.Any, files: Optional[List[discohook.file.File]] = typing.Any, suppress_embeds: Optional[bool] = typing.Any) discohook.message.Message[source]#
Edits the response message.
:param same as
Message.edit():
- class discohook.InteractionType(value)[source]#
Bases:
int,enum.EnumThe type of interaction received from discord.
Used internally by the library. You should not need to use this.
- app_command = 2#
- autocomplete = 4#
- component = 3#
- modal_submit = 5#
- ping = 1#
- class discohook.Member(client: Client, data: Dict[str, Any])[source]#
Bases:
discohook.user.UserRepresents a member of a guild, subclassed from
User.- async add_role(role_id: str, *, reason: Optional[str] = None)[source]#
Add a role to the member.
- Parameters
role_id (str) – The ID of the role.
reason (Optional[str]) – The reason for adding the role to be logged.
- property avatar: discohook.asset.Asset#
- 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 disabled_until: Optional[str]#
- property flags: int#
- property guild_id: str#
- has_permission(permission: discohook.permission.Permission) bool[source]#
- property joined_at: str#
- property mention: str#
Returns a string that allows you to mention the member.
- property nick: str#
- property pending: bool#
- property permissions: int#
- async remove_role(role_id: str)[source]#
Remove a role from the member.
- Parameters
role_id (str) – The ID of the role.
- property roles: List[discohook.role.PartialRole]#
- class discohook.Message(client: Client, payload: Dict[str, Any])[source]#
Bases:
objectRepresents a Discord message.
- 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. …
- property activity: Optional[dict]#
- async add_reaction(emoji: Union[discohook.emoji.PartialEmoji, str])[source]#
Creates a reaction on the message.
- Parameters
emoji (Union[Emoji, str]) – The emoji to react with.
- property application: Optional[dict]#
- property application_id: Optional[str]#
- property attachments: Optional[List[discohook.attachment.Attachment]]#
- property author: discohook.user.User#
- property channel_id: str#
- property components: Optional[List[dict]]#
- property content: Optional[str]#
- async edit(content: Optional[str] = typing.Any, *, embed: Optional[discohook.embed.Embed] = typing.Any, embeds: Optional[List[discohook.embed.Embed]] = typing.Any, view: Optional[discohook.view.View] = typing.Any, tts: Optional[bool] = typing.Any, file: Optional[discohook.file.File] = typing.Any, files: Optional[List[discohook.file.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.
- property edited_timestamp: Optional[str]#
- property embeds: Optional[List[discohook.embed.Embed]]#
- property flags: Optional[int]#
- property id: str#
- property interaction: Optional[discohook.message.MessageInteraction]#
- property mention_channels: Optional[dict]#
- property mention_everyone: bool#
- property mention_roles: List[discohook.role.Role]#
- property mentions: List[discohook.user.User]#
- property message_reference: Optional[dict]#
- property nonce: Optional[str]#
- property pinned: bool#
- property poll: Optional[discohook.poll.Poll]#
- property position: Optional[int]#
- property reactions: Optional[List[dict]]#
- property referenced_message: Optional[dict]#
- async remove_reaction(emoji: Union[discohook.emoji.PartialEmoji, str], user_id: Optional[str] = None)[source]#
Removes a reaction on the message.
- Parameters
emoji (Union[Emoji, str]) – The emoji to delete.
user_id (Optional[str]) – The user to delete the reaction of.
- async remove_reactions(emoji: Optional[Union[str, discohook.emoji.PartialEmoji]] = None)[source]#
Removes all reactions on the message.
- Parameters
emoji (Union[Emoji, str, None]) – The emoji to remove reactions of.
- async reply(content: Optional[str] = None, *, embed: Optional[discohook.embed.Embed] = None, embeds: Optional[List[discohook.embed.Embed]] = None, view: Optional[discohook.view.View] = None, tts: Optional[bool] = False, file: Optional[discohook.file.File] = None, files: Optional[List[discohook.file.File]] = None, allowed_mentions: Optional[discohook.models.AllowedMentions] = None, mention_author: Optional[bool] = None, poll: Optional[discohook.poll.Poll] = None)[source]#
Replies to the message.
- Parameters
content (Optional[str]) – The content of the message.
embed (Optional[Embed]) – The embed of the message.
embeds (Optional[List[Embed]]) – The embeds of the message.
view (Optional[View]) – The 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.
allowed_mentions (Optional[AllowedMentions]) – The allowed mentions for the message.
mention_author (Optional[bool]) – Whether the author should be mentioned.
poll (Optional[Poll]) – The poll to send with the message.
- Return type
- async start_thread(name: str, *, auto_archive_duration: int = 60, rate_limit_per_user: int = 0, reason: Optional[str] = None) aiohttp.client_reqrep.ClientResponse[source]#
Starts a thread from the message.
- Parameters
name (str) – The name of the thread.
auto_archive_duration (int) – The duration of the thread in minutes.
rate_limit_per_user (int) – The rate limit per user in seconds.
reason (Optional[str]) – The reason for starting the thread.
- Return type
aiohttp.ClientResponse
- property sticker_items: Optional[List[dict]]#
- property stickers: Optional[List[dict]]#
- property thread: Optional[dict]#
- property timestamp: str#
- property tts: bool#
- property type: int#
- property webhook_id: Optional[str]#
- id:
- class discohook.MessageReference(message_id: Optional[str] = None, channel_id: Optional[str] = None, guild_id: Optional[str] = None, fail_if_not_exists: Optional[bool] = None)[source]#
Bases:
objectRepresents a discord message reference object.
- Parameters
message_id (str | None) – The id of the message.
channel_id (str | None) – The id of the channel where the message was sent.
guild_id (str | None) – The id of the guild where the message was sent.
fail_if_not_exists (bool | None) – Whether to throw an error if the message does not exist.
- class discohook.Modal(title: str, *, custom_id: Optional[str] = None)[source]#
Bases:
discohook.component.ComponentA 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: discohook.enums.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.ModalFieldType(value)[source]#
Bases:
int,enum.EnumThe type of field in a modal.
Used internally by the library. You should not need to use this.
- text_input#
Used to specify a text input field.
- Type
int
- text_input = 4#
- class discohook.Option(name: str, description: str, *, required: bool = False, kind: discohook.enums.ApplicationCommandOptionType)[source]#
Bases:
objectRepresents a base option for an application command.
- Parameters
name (str) – The name of the option. Must be a valid python identifier.
description (str) – The description of the option.
required (bool) – Whether the option is required or not.
kind (AppCmdOptionType) – The type of the option.
- classmethod channel(name: str, description: str, *, required: Optional[bool] = False, types: Optional[List[discohook.enums.ChannelType]] = None)[source]#
- classmethod integer(name: str, description: str, *, required: Optional[bool] = False, max_value: Optional[int] = None, min_value: Optional[int] = None, choices: Optional[List[discohook.option.Choice]] = None, autocomplete: Optional[bool] = False)[source]#
- classmethod number(name: str, description: str, *, required: Optional[bool] = False, max_value: Optional[float] = None, min_value: Optional[float] = None, choices: Optional[List[discohook.option.Choice]] = None, autocomplete: Optional[bool] = False)[source]#
- classmethod string(name: str, description: str, *, required: Optional[bool] = False, max_length: Optional[int] = None, min_length: Optional[int] = None, choices: Optional[List[discohook.option.Choice]] = None, autocomplete: Optional[bool] = False)[source]#
- class discohook.PartialChannel(client: Client, channel_id: str, guild_id: Optional[str] = None)[source]#
Bases:
objectRepresents a partial discord channel object.
- Parameters
channel_id (str) – The channel’s ID.
guild_id (str | None) – The guild’s ID.
client (
Client) – The client that the channel belongs to.
- async edit(*, name: Optional[str] = None, kind: Optional[discohook.enums.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[discohook.emoji.PartialEmoji] = None, default_thread_rate_limit_per_user: Optional[int] = None, default_sort_order: Optional[int] = None, default_forum_layout: Optional[int] = None) discohook.channel.Channel[source]#
Edits all kinds of channels.
- Parameters
name (Optional[
str]) – The new name of the channel.kind (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
- async fetch_message(message_id: str) Optional[discohook.message.Message][source]#
Fetches a message from the channel.
- Parameters
message_id (
str) – The id of the message to fetch.- Returns
The fetched message.
- Return type
- async fetch_messages(limit: int = 50, *, before: Optional[str] = None, after: Optional[str] = None, around: Optional[str] = None) List[discohook.message.Message][source]#
Fetches messages from the channel.
- Parameters
limit (Optional[
int]) – The maximum amount of messages to fetch.before (Optional[
str]) – The id of the message to fetch before.after (Optional[
str]) – The id of the message to fetch after.around (Optional[
str]) – The id of the message to fetch around.
- Returns
The fetched messages.
- Return type
List[
Message]
- property mention: str#
Returns the channel-mentionable string.
- Return type
str
- async purge(limit: int = 50, *, before: Optional[str] = None, after: Optional[str] = None, around: Optional[str] = None) List[discohook.message.Message][source]#
Deletes messages from the channel in bulk.
- Parameters
limit (Optional[
int]) – The maximum amount of messages to delete.before (Optional[
str]) – The id of the message to delete before.after (Optional[
str]) – The id of the message to delete after.around (Optional[
str]) – The id of the message to delete around.
- Returns
The deleted messages.
- Return type
List[
Message]
- async send(content: Optional[str] = None, *, embed: Optional[discohook.embed.Embed] = None, embeds: Optional[List[discohook.embed.Embed]] = None, view: Optional[discohook.view.View] = None, tts: Optional[bool] = False, file: Optional[discohook.file.File] = None, files: Optional[List[discohook.file.File]] = None, poll: Optional[discohook.poll.Poll] = None, allowed_mentions: Optional[discohook.models.AllowedMentions] = None, message_reference: Optional[discohook.models.MessageReference] = 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.
poll (Optional[
Poll]) – The poll to send with the message.allowed_mentions (Optional[
AllowedMentions]) – The allowed mentions for the message.message_reference (Optional[
MessageReference]) – The message reference for the message.
- async start_thread(name: str, *, auto_archive_duration: int = 60, invitable: bool = True, rate_limit_per_user: int = 0, reason: Optional[str] = None) discohook.channel.Channel[source]#
Creates a thread from the channel.
- Parameters
name (
str) – The name of the thread.auto_archive_duration (Optional[
int]) – The duration in minutes to automatically archive the thread after recent activity.invitable (Optional[
bool]) – Whether non-moderators can add other non-moderators to the thread.rate_limit_per_user (Optional[
int]) – Amount of seconds a user has to wait before sending another message (0-21600)reason –
- class discohook.PartialEmoji(*, name: Optional[str] = None, id: Optional[str] = None, animated: Optional[bool] = None)[source]#
Bases:
objectRepresents 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.
- classmethod from_str(value: str) discohook.emoji.PartialEmoji[source]#
Creates a partial emoji from a string formatted emoji.
- Parameters
value (
str) – The string formatted emoji.
- class discohook.PartialGuild(client: Client, guild_id: str)[source]#
Bases:
objectRepresents a partial guild.
- async create_channel(name: str, *, type: discohook.enums.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[discohook.emoji.PartialEmoji] = None, available_tags: Optional[List[Dict[str, Any]]] = None, default_sort_order: Optional[int] = None) discohook.channel.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 create_emoji(name: str, image: str, *, roles: Optional[List[str]] = None)[source]#
Creates a new emoji for the guild.
- Parameters
name (
str) – The name of the emoji.image (
str) – The image data of the emoji in base64 data uri format.roles (Optional[List[
str]]) – A list of role ids to limit the emoji to.
- Return type
Emoji
- async create_role(name: str, *, permissions: Optional[List[discohook.permission.Permission]] = None, color: int = 0, hoist: bool = False, mentionable: Optional[bool] = False, icon_data_uri: Optional[str] = None, unicode_emoji: Optional[str] = None)[source]#
- 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.
- async fetch_channels() List[discohook.channel.Channel][source]#
Fetches all channels in the guild.
- Return type
List[Channel]
- async fetch_member(user_id: str) Optional[discohook.member.Member][source]#
Fetches a member from the guild.
- Parameters
user_id (
str) – The id of the user to fetch.- Return type
Optional[
Member]
- async fetch_roles() List[discohook.role.Role][source]#
Fetches all roles in the guild.
- Return type
List[Role]
- class discohook.PartialRole(client: Client, data: Dict[str, Any])[source]#
Bases:
object- async edit(*, name: Optional[str] = None, permissions: Optional[List[discohook.permission.Permission]] = 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) discohook.role.Role[source]#
Edits the role.
- Parameters
name (Optional[
str]) – The name of the role.permissions (Optional[
Permission]) – 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[discohook.role.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.PartialWebhook(id: str, token: str, *, session: Optional[aiohttp.client.ClientSession] = None, api_version: int = 10)[source]#
Bases:
object- classmethod from_url(url: str, *, session: Optional[aiohttp.client.ClientSession] = None, api_version: int = 10) discohook.webhook.PartialWebhook[source]#
- async send(content: Optional[str] = None, *, username: Optional[str] = None, avatar_url: Optional[str] = None, embed: Optional[discohook.embed.Embed] = None, embeds: Optional[List[discohook.embed.Embed]] = None, file: Optional[discohook.file.File] = None, files: Optional[List[discohook.file.File]] = None, tts: bool = False, thread_name: Optional[str] = None, wait: bool = False, thread_id: Optional[str] = None) aiohttp.client_reqrep.ClientResponse[source]#
Sends a message to the webhook. :param content: The content of the message. :type content: Optional[
str] :param username: The username of the webhook. :param avatar_url: The avatar url of the webhook. (Overrides the webhook’s avatar) :param embed: The embed of the message. :type embed: Optional[Embed] :param embeds: The embeds of the message. :type embeds: Optional[List[Embed]] :param file: The file of the message. :type file: Optional[File] :param files: The files of the message. :param tts: Whether the message should be sent with text-to-speech. :type tts:bool:param thread_name: The name of the thread to create. :type thread_name: Optional[str] :param wait: Waits for server confirmation of the message. :type wait:bool:param thread_id: Whether to send to a specified thread within the webhook’s channel. :type thread_id: Optional[str]- Return type
aiohttp.ClientResponse
- class discohook.Permission(value)[source]#
Bases:
enum.EnumRepresents discord permission values.
- add_reactions = 64#
- administrator = 8#
- attach_files = 32768#
- ban_members = 4#
- change_nickname = 67108864#
- static check(permissions: int, permission: discohook.permission.Permission) bool[source]#
- connect = 1048576#
- create_instant_invite = 1#
- create_private_threads = 68719476736#
- create_public_threads = 34359738368#
- deafen_members = 8388608#
- embed_links = 16384#
- kick_members = 2#
- manage_channels = 16#
- manage_emojis_and_stickers = 1073741824#
- manage_events = 8589934592#
- manage_guild = 32#
- manage_messages = 8192#
- manage_nicknames = 134217728#
- manage_roles = 268435456#
- manage_threads = 17179869184#
- manage_webhooks = 536870912#
- mention_everyone = 131072#
- moderate_members = 1099511627776#
- move_members = 16777216#
- mute_members = 4194304#
- priority_speaker = 256#
- read_message_history = 65536#
- request_to_speak = 4294967296#
- send_messages = 2048#
- send_messages_in_threads = 274877906944#
- send_tts_messages = 4096#
- speak = 2097152#
- stream = 512#
- use_application_commands = 2147483648#
- use_embedded_activities = 549755813888#
- use_external_emojis = 262144#
- use_external_stickers = 137438953472#
- use_vad = 33554432#
- view_audit_log = 128#
- view_channel = 1024#
- view_guild_insights = 524288#
- class discohook.Poll(data: Dict[str, Any])[source]#
Bases:
objectA poll object.
- question: Optional[
str] The question of the poll.
- answers: Optional[List[
PollAnswer]] The answers to the poll.
- expiry: Optional[
int] The expiry time of the poll.
- allow_multiselect:
bool Whether the poll allows multiple answers.
- layout:
PollLayoutType The layout of the poll.
- property allow_multiselect: bool#
- property answer_counts: Optional[List[discohook.poll.PollAnswerCount]]#
- property answers: Optional[List[discohook.poll.PollAnswer]]#
- property expiry: Optional[int]#
- async fetch_all_voters() Dict[int, List[discohook.user.User]][source]#
Fetch all the answers of the poll. :rtype: Dict[
int, List[User]]
- async fetch_voters(answer_id: int, *, after: Optional[str] = None, limit: int = 25) List[discohook.user.User][source]#
Fetch the voters of an answer with pagination. :param answer_id: The ID of the answer. :type answer_id:
int:param after: The ID of the last user fetched. :type after: Optional[str] :param limit: The number of users to fetch. Maximum is 100. :type limit:int- Return type
List[
User]
- property is_finalized: bool#
- property layout: discohook.enums.PollLayoutType#
- classmethod new(question: str, *answers: discohook.poll.PollAnswer, expiry: Optional[int] = None, allow_multiselect: bool = False, layout: int = PollLayoutType.default) discohook.poll.Poll[source]#
- property question: Optional[str]#
- question: Optional[
- class discohook.PollAnswer(data: Dict[str, Any])[source]#
Bases:
objectAn answer to a poll.
- answer_id:
int The ID of the answer.
- poll_media: Optional[
PollMedia] The media of the answer.
- property id: int#
- property media: discohook.poll.PollMedia#
- classmethod new(answer_id: int, media: Union[str, discohook.poll.PollMedia]) discohook.poll.PollAnswer[source]#
Create a new poll answer. :param answer_id: The ID of the answer. :type answer_id:
int:param media: The media of the answer. :type media: Union[str,PollMedia]- Returns
The newly created poll answer.
- Return type
- answer_id:
- class discohook.PollAnswerCount(data: Dict[str, Any])[source]#
Bases:
objectRepresents the count of an answer in a poll.
- answer_id:
int The ID of the answer.
- count:
int The count of the answer.
- property answer_id: int#
- property count: int#
- answer_id:
- class discohook.PollLayoutType(value)[source]#
Bases:
int,enum.EnumThe type of layout for a poll.
- default#
Used to specify the default layout.
- Type
int
- default = 1#
- class discohook.PollMedia(data: Dict[str, Any])[source]#
Bases:
objectThe question of the poll. Only text is supported.
- text: Optional[
str] The text of the media.
- emoji: Optional[
PartialEmoji] The emoji of the media.
- property emoji: Optional[discohook.emoji.PartialEmoji]#
- classmethod from_str(text: str) discohook.poll.PollMedia[source]#
- property text: Optional[str]#
- text: Optional[
- class discohook.Role(client: Client, data: dict)[source]#
Bases:
discohook.role.PartialRoleRepresents 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(permission: discohook.permission.Permission) bool[source]#
Checks if the role has the given permissions.
- Parameters
permission (
Permission) – The permissions to check.- Return type
bool
- class discohook.Select(type: discohook.enums.SelectType, *, placeholder: Optional[str] = None, min_values: Optional[int] = None, max_values: Optional[int] = None, disabled: Optional[bool] = False, custom_id: Optional[str] = None)[source]#
Bases:
discohook.component.ComponentRepresents a discord select menu component.
- Parameters
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.SelectDefaultValueType(value)[source]#
Bases:
str,enum.EnumThe type of default value for a select menu.
Used internally by the library. You should not need to use this.
- channel = 'channel'#
- role = 'role'#
- user = 'user'#
- class discohook.SelectOption(label: str, value: str, *, description: Optional[str] = None, emoji: Optional[Union[str, discohook.emoji.PartialEmoji]] = None, default: bool = False)[source]#
Bases:
objectRepresents 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.SelectType(value)[source]#
Bases:
int,enum.EnumThe type of select menu.
- channel = 8#
- mentionable = 7#
- role = 6#
- text = 3#
- user = 5#
- class discohook.SubCommand(name: str, description: str, options: Optional[List[discohook.option.Option]] = None, *, callback: Optional[Callable[[Interaction, Any], Coroutine[[Any, Any], Any]]] = None)[source]#
Bases:
objectA 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 (AsyncCallable | None) – The callback of the subcommand.
- on_autocomplete(coro: Callable[[Interaction, Any], Coroutine[[Any, Any], Any]])[source]#
A decorator to register a callback for the subcommand’s autocomplete options.
- class discohook.TextInput(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: discohook.enums.TextInputFieldLength = TextInputFieldLength.short)[source]#
Bases:
objectRepresents a text input field in a modal.
- Parameters
label (
str) – The label of the text input field.field_id (
str) – A unique id of the text input field. Must be valid python identifier.required (
bool) – Whether the text input field is required.hint (
str) – The hint of the text input field.default_text (
str) – The default text of the text input field.min_length (
int) – The minimum length of the text input field.max_length (
int) – The maximum length of the text input field.style (
TextInputFieldLength) – The style of the text input field.
- class discohook.TextInputFieldLength(value)[source]#
Bases:
int,enum.EnumThe 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
- long = 2#
- short = 1#
- class discohook.User(client: Client, data: Dict[str, Any])[source]#
Bases:
objectRepresents a discord user.
- id:
str The unique ID of the user.
- name:
str The name of the user.
- discriminator:
str The discriminator of the user.
- accent_color: Optional[
int] The accent color 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.
- property accent_color: Optional[int]#
- property avatar: discohook.asset.Asset#
- property bot: bool#
- property discriminator: int#
- property email: Optional[str]#
- property global_name: Optional[str]#
- property id: str#
- property locale: Optional[str]#
- property mention: str#
- property mfa_enabled: bool#
- property name: str#
- property public_flags: Optional[int]#
- async send(content: str, *, tts: bool = False, embed: Optional[discohook.embed.Embed] = None, embeds: Optional[List[discohook.embed.Embed]] = None, file: Optional[discohook.file.File] = None, files: Optional[List[discohook.file.File]] = None) aiohttp.client_reqrep.ClientResponse[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.
- property system: bool#
- property verified: bool#
- id:
- class discohook.View[source]#
Bases:
objectRepresents 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.
- add_buttons(*buttons: Union[discohook.button.Button, Any])[source]#
Adds a row of buttons to the view. Each row can only contain up to 5 buttons. Action rows having buttons can not have select menus.
- Parameters
*buttons (
Button) – The buttons to be added to the view.
- add_select(select: Union[discohook.select.Select, Any])[source]#
Adds a row of select to the view. Each row can only contain up to 1 select menu. Action rows having select menu can not have buttons.
- Parameters
select (
Select) – The select menu to be added to the view.
- class discohook.Webhook(client: Client, data: dict)[source]#
Bases:
objectRepresents a Discord Application Owned Webhook.
- id:
str The id of the webhook.
- type:
int The type of the webhook.
- guild_id: Optional[
str] The id of the guild the webhook is in.
- channel_id: Optional[
str] The id of the channel the webhook is in.
- name: Optional[
str] The name of the webhook.
- avatar: Optional[
Asset] The avatar of the webhook.
- token: Optional[
str] The token of the webhook.
- application_id: Optional[
str] The id of the application the webhook belongs to.
- source_guild: Optional[
PartialGuild] The source guild of the webhook.
- source_channel: Optional[
PartialChannel] The source channel of the webhook.
- url:
str The url of the webhook.
- property application_id: Optional[str]#
- property avatar: Optional[discohook.asset.Asset]#
- property channel_id: Optional[str]#
- async delete_message(message_id: str) aiohttp.client_reqrep.ClientResponse[source]#
Deletes a message from the webhook.
- Parameters
message_id (
str) – The id of the message to delete.- Return type
aiohttp.ClientResponse
- async edit(name: Optional[str] = None, image_base64: Optional[str] = None, channel_id: Optional[str] = None) discohook.webhook.Webhook[source]#
Edits the webhook.
- Parameters
name (Optional[
str]) – The new name of the webhook.image_base64 (Optional[
str]) – The new avatar of the webhook.channel_id (Optional[
str]) – The new channel id of the webhook.
- Return type
Notes
The image must be a base64 encoded string. All parameters are optional.
- async edit_message(message_id: str, *, content: Optional[str] = typing.Any, embed: Optional[discohook.embed.Embed] = typing.Any, embeds: Optional[List[discohook.embed.Embed]] = typing.Any, file: Optional[discohook.file.File] = typing.Any, files: Optional[List[discohook.file.File]] = typing.Any, view: Optional[discohook.view.View] = typing.Any) discohook.message.Message[source]#
Edits a message from the webhook.
- Parameters
message_id (
str) – The id of the message to edit.content (Optional[
str]) – The new content of the message.embed (Optional[
Embed]) – The new embed to be sent with the message.embeds (Optional[List[
Embed]]) – The new embeds to be sent with the message.file (Optional[
File]) – The new file to be sent with the message.files (Optional[List[
File]]) – The new files to be sent with the message.view (Optional[
View]) – The new view to be sent with the message.
- Return type
- property guild_id: Optional[str]#
- property id: str#
- property name: Optional[str]#
- async send(content: Optional[str] = None, *, username: Optional[str] = None, avatar_url: Optional[str] = None, embed: Optional[discohook.embed.Embed] = None, embeds: Optional[List[discohook.embed.Embed]] = None, file: Optional[discohook.file.File] = None, files: Optional[List[discohook.file.File]] = None, tts: bool = False, view: Optional[discohook.view.View] = None, thread_name: Optional[str] = None)[source]#
Sends a message to the webhook. :param content: The content of the message. :type content: Optional[
str] :param username: The username of the webhook. :param avatar_url: The avatar url of the webhook. (Overrides the webhook’s avatar) :param embed: The embed of the message. :type embed: Optional[Embed] :param embeds: The embeds of the message. :type embeds: Optional[List[Embed]] :param file: The file of the message. :type file: Optional[File] :param files: The files of the message. :param tts: Whether the message should be sent with text-to-speech. :type tts:bool:param view: The view to be sent with the message. :type view: Optional[View] :param thread_name: The name of the thread to create. :type thread_name: Optional[str]- Return type
None
- property source_channel: Optional[discohook.channel.PartialChannel]#
- property source_guild: Optional[discohook.guild.PartialGuild]#
- property token: Optional[str]#
- property type: int#
- property url: Optional[str]#
- property user: Optional[discohook.user.User]#
- id: