View¶
discord_http.view module¶
- class discord_http.view.ActionRow(*components)¶
Bases:
ItemRepresents an action row component in a message, containing buttons, selects, and links.
- type: ComponentType¶
The type of the component.
- class discord_http.view.AttachmentComponent(*, state, data)¶
Bases:
objectRepresents an attachment component.
- Parameters:
state (DiscordAPI)
data (dict)
- async fetch(*, use_cached=False) bytes¶
Fetches the file from the attachment URL and returns it as bytes.
- Parameters:
use_cached (
bool) – Whether to use the cached URL or not, defaults to False- Return type:
- Returns:
The attachment as bytes
- Raises:
HTTPException – If the request returned anything other than 2XX
- async save(path, *, use_cached=False) int¶
Fetches the file from the attachment URL and saves it locally to the path.
- class discord_http.view.Button(*, label=None, style=ButtonStyles.primary, disabled=False, custom_id=None, sku_id=None, emoji=None, url=None)¶
Bases:
ItemRepresents a button component in a message.
- Parameters:
- style: ButtonStyles | str | int¶
The style of the button.
- type: ComponentType¶
The type of the component.
- class discord_http.view.ChannelSelect(channel_types, placeholder=None, custom_id=None, min_values=1, max_values=1, default_values=None, disabled=False, label=None, description=None, required=False)¶
Bases:
SelectRepresents a channel select menu component in a message.
- Parameters:
- channel_types¶
The channel types that can be selected.
- add_item(*, label, value, description=None, emoji=None, default=False) None¶
Add an item to the select menu.
- Parameters:
- Raises:
ValueError – If there are more than 25 options
- Return type:
- options¶
- type: ComponentType¶
The type of the component.
- class discord_http.view.CheckboxComponent(*, custom_id=None, label=None, description=None, default=False)¶
Bases:
ItemRepresents a checkbox component in a modal.
This is a single checkbox component, and returns a boolean value on interaction.
- type: ComponentType¶
The type of the component.
- class discord_http.view.CheckboxGroupComponent(*options, custom_id=None, label=None, description=None, min_values=1, max_values=None, required=True)¶
Bases:
ItemRepresents a checkbox group component in a modal.
- Parameters:
- options: list[ComponentOption]¶
The options for the checkbox group component.
- add_item(value, label, description=None, default=False) None¶
Add an item to the checkbox group component.
- Parameters:
- Return type:
- type: ComponentType¶
The type of the component.
- class discord_http.view.ComponentOption(*, label, value, description=None, default=False)¶
Bases:
objectRepresents an option for radio and checkbox components.
- label¶
The label of the option.
- value¶
The value of the option.
- description¶
The description of the option.
- default¶
Whether the option is the default selection.
- class discord_http.view.ContainerComponent(*items, colour=None, spoiler=None)¶
Bases:
ItemRepresents a container component in a message.
- type: ComponentType¶
The type of the component.
- class discord_http.view.FileComponent(file, *, spoiler=False)¶
Bases:
ItemRepresents a file component in a message.
- Parameters:
file (Asset | AttachmentComponent | str)
spoiler (bool)
- type: ComponentType¶
The type of the component.
- file: Asset | AttachmentComponent | str¶
The file to be sent.
- class discord_http.view.FileUploadComponent(*, custom_id=None, min_values=None, max_values=None, label=None, description=None, required=True)¶
Bases:
ItemRepresents a file upload component in a modal.
- Parameters:
- type: ComponentType¶
The type of the component.
- class discord_http.view.Item(*, type)¶
Bases:
objectBase class for all components in discord.http API.
- Parameters:
type (ComponentType)
- type: ComponentType¶
The type of the component.
- class discord_http.view.Link(*, url, label=None, emoji=None, disabled=False)¶
Bases:
ButtonButton alias for the link style.
- style: ButtonStyles | str | int¶
The style of the button.
- type: ComponentType¶
The type of the component.
- class discord_http.view.MediaGalleryComponent(*items)¶
Bases:
ItemRepresents a media gallery component in a message.
- Parameters:
items (MediaGalleryItem | File | Asset | str)
- type: ComponentType¶
The type of the component.
- class discord_http.view.MediaGalleryItem(url, *, description=None, spoiler=False)¶
Bases:
objectRepresents an item in a media gallery.
- url: File | Asset | AttachmentComponent | str¶
The URL of the media item, can be a file, asset, attachment component, or a string URL.
- class discord_http.view.MentionableSelect(*, placeholder=None, custom_id=None, min_values=1, max_values=1, default_values=None, disabled=False, label=None, description=None, required=False)¶
Bases:
SelectRepresents a mentionable select menu component in a message.
- Parameters:
- add_item(*, label, value, description=None, emoji=None, default=False) None¶
Add an item to the select menu.
- Parameters:
- Raises:
ValueError – If there are more than 25 options
- Return type:
- options¶
- type: ComponentType¶
The type of the component.
- class discord_http.view.Modal(*, title, custom_id=None)¶
Bases:
InteractionStorageRepresents a modal component in a message.
- loop¶
- async wait(ctx, *, call_after=None, users=None, original_response=False, custom_id=None, timeout=60) Context | None¶
Tell the command to wait for an interaction response.
It will continue your code either if it was interacted with or timed out
- Parameters:
ctx (
Context) – Passing the current context of the botcall_after (
Callable|None) –Coroutine to call after the view is interacted with (will be ignored if timeout) The new context does follow with the call_after function, example:
test = await view.wait(ctx, call_after=call_after, timeout=10) if not test: return None # Timed out async def call_after(ctx): await ctx.response.edit_message(content="Hello world")
users (
list[Snowflake] |None) – List of users that are allowed to interact with the vieworiginal_response (
bool) – Whether to force the original response to be used as the message targetcustom_id (
str|int|None) – Custom ID of the view, if not provided, it will use Context.id or Context.messagetimeout (
float) – How long it should take until the code simply times out
- Return type:
- Returns:
Returns the new context of the interaction, or None if timed out
- items: list[TextDisplayComponent | LabelComponent | FileUploadComponent]¶
The items contained within the modal.
- add_item(component, *, label=None, description=None) LabelComponent | TextDisplayComponent¶
Add an item to the modal.
- Parameters:
component (
TextDisplayComponent|TextInputComponent|Select|FileUploadComponent|RadioComponent|CheckboxGroupComponent|CheckboxComponent) – The component to add to the modal.label (
str|None) – The label of the component, overwrites component.labeldescription (
str|None) – The description of the component, overwrites component.description, by default None
- Return type:
LabelComponent|TextDisplayComponent- Returns:
The created label component
- Raises:
TypeError – If the component is not a TextInputComponent or Select
- class discord_http.view.Premium(sku_id)¶
Bases:
ButtonButton alias for the premium SKU style.
- style: ButtonStyles | str | int¶
The style of the button.
- type: ComponentType¶
The type of the component.
- class discord_http.view.RadioComponent(*options, custom_id, label=None, description=None, required=True)¶
Bases:
ItemRepresents a radio button component in a modal.
- Parameters:
options (ComponentOption)
custom_id (str)
label (str | None)
description (str | None)
required (bool)
- options¶
The options for the radio component.
- add_item(value, label, description=None, default=False) None¶
Add an item to the radio component.
- Parameters:
value (
str) – The value of the option, which will be returned on interaction responselabel (
str) – The label of the option, what the user seesdescription (
str|None) – The description of the option, additional text shown below the labeldefault (
bool) – Whether the option is the default selection
- Return type:
- type: ComponentType¶
The type of the component.
- class discord_http.view.RoleSelect(*, placeholder=None, custom_id=None, min_values=1, max_values=1, default_values=None, disabled=False, label=None, description=None, required=False)¶
Bases:
SelectRepresents a role select menu component in a message.
- Parameters:
- add_item(*, label, value, description=None, emoji=None, default=False) None¶
Add an item to the select menu.
- Parameters:
- Raises:
ValueError – If there are more than 25 options
- Return type:
- options¶
- type: ComponentType¶
The type of the component.
- class discord_http.view.SectionComponent(*components, accessory)¶
Bases:
ItemRepresents a section component in a message.
- Parameters:
components (TextDisplayComponent | str)
accessory (Button | ThumbnailComponent | AttachmentComponent | Asset | File | str)
- components: list[TextDisplayComponent | str]¶
The components contained within the section.
- accessory: Button | ThumbnailComponent | AttachmentComponent | Asset | File | str¶
The accessory component for the section.
- type: ComponentType¶
The type of the component.
- class discord_http.view.Select(*, label=None, description=None, placeholder=None, custom_id=None, min_values=1, max_values=1, disabled=False, options=None, required=None, _type=None)¶
Bases:
ItemRepresents a select menu component in a message.
- Parameters:
- add_item(*, label, value, description=None, emoji=None, default=False) None¶
Add an item to the select menu.
- Parameters:
- Raises:
ValueError – If there are more than 25 options
- Return type:
- options¶
- type: ComponentType¶
The type of the component.
- class discord_http.view.SeparatorComponent(*, spacing=None, divider=None)¶
Bases:
ItemRepresents a separator component in a message.
- Parameters:
spacing (SeparatorSpacingType | None)
divider (bool | None)
- spacing: SeparatorSpacingType | None¶
The spacing type of the separator.
- type: ComponentType¶
The type of the component.
- class discord_http.view.TextDisplayComponent(content)¶
Bases:
ItemRepresents a text display component in a message.
- Parameters:
content (str)
- content¶
The content of the text display component.
- type: ComponentType¶
The type of the component.
- class discord_http.view.TextInputComponent(*, label=None, description=None, custom_id=None, style=None, placeholder=None, min_length=None, max_length=None, default=None, required=True)¶
Bases:
ItemRepresents a text input component in a modal.
- Parameters:
- type: ComponentType¶
The type of the component.
- class discord_http.view.ThumbnailComponent(url, *, description=None, spoiler=False)¶
Bases:
ItemRepresents a thumbnail component in a message.
- Parameters:
url (Asset | AttachmentComponent | str)
description (str | None)
spoiler (bool)
- url: Asset | AttachmentComponent | str¶
The URL of the thumbnail image.
- type: ComponentType¶
The type of the component.
- class discord_http.view.UserSelect(*, placeholder=None, custom_id=None, min_values=1, max_values=1, default_values=None, disabled=False, label=None, description=None, required=False)¶
Bases:
SelectRepresents a user select menu component in a message.
- Parameters:
- add_item(*, label, value, description=None, emoji=None, default=False) None¶
Add an item to the select menu.
- Parameters:
- Raises:
ValueError – If there are more than 25 options
- Return type:
- options¶
- type: ComponentType¶
The type of the component.
- class discord_http.view.View(*items)¶
Bases:
InteractionStorageRepresents a view component in a message.
- Parameters:
items (Item)
- loop¶
- async wait(ctx, *, call_after=None, users=None, original_response=False, custom_id=None, timeout=60) Context | None¶
Tell the command to wait for an interaction response.
It will continue your code either if it was interacted with or timed out
- Parameters:
ctx (
Context) – Passing the current context of the botcall_after (
Callable|None) –Coroutine to call after the view is interacted with (will be ignored if timeout) The new context does follow with the call_after function, example:
test = await view.wait(ctx, call_after=call_after, timeout=10) if not test: return None # Timed out async def call_after(ctx): await ctx.response.edit_message(content="Hello world")
users (
list[Snowflake] |None) – List of users that are allowed to interact with the vieworiginal_response (
bool) – Whether to force the original response to be used as the message targetcustom_id (
str|int|None) – Custom ID of the view, if not provided, it will use Context.id or Context.messagetimeout (
float) – How long it should take until the code simply times out
- Return type:
- Returns:
Returns the new context of the interaction, or None if timed out
- get_item(*, label=None, custom_id=None) Item | None¶
Get an item from the view that matches the parameters.
- remove_items(*, label=None, custom_id=None) int¶
Remove items from the view that match the parameters.
- classmethod from_dict(*, state, data) View¶
Returns a view from a dict provided by Discord.
- Return type:
- Parameters:
state (DiscordAPI)
data (dict)