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)
- content_scan_flags: ContentScanFlags | None¶
The flags from Discord’s content scanning, if the media has been scanned.
- async fetch(*, use_cached=False) bytes¶
Fetches the file from the attachment URL and returns it as bytes.
Media that was not uploaded to Discord points at whatever URL the author of the message chose. That is always fetched through Discord’s proxy, so the bot never connects to a host picked by a user.
- 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: list[ChannelType]¶
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.CheckpointComponent(*_, **kwargs)¶
Bases:
LockedItemRepresents a checkpoint component in a message.
This is used for the checkpoint feature in Discord.
- 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.
- 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.ContentInventoryEntry(*_, **kwargs)¶
Bases:
LockedItemRepresents a content inventory entry component in a message.
This is used for the content inventory feature in Discord.
- 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 (File | Asset | AttachmentComponent | str)
spoiler (bool)
- type: ComponentType¶
The type of the component.
- file: 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, file_types=None)¶
Bases:
ItemRepresents a file upload component in a modal.
- Parameters:
- file_types: list[str] | None¶
List of allowed extensions, can be image, video, audio or any dot-prefixed extensions such as .pdf
- 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.LabelComponent(*, label, description=None, component)¶
Bases:
ItemRepresents a label component in a modal.
- Parameters:
label (str | None)
description (str | None)
component (TextInputComponent | Select | FileUploadComponent | RadioComponent | CheckboxGroupComponent | CheckboxComponent)
- type: ComponentType¶
The type of the component.
- component: TextInputComponent | Select | FileUploadComponent | RadioComponent | CheckboxGroupComponent | CheckboxComponent¶
The component contained within the label.
- 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.LockedItem(*, type, **kwargs)¶
Bases:
ItemUsed for valid components, but cannot be used directly.
- Parameters:
type (ComponentType)
kwargs (dict)
- 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.
- add_item(item, *, description=None, spoiler=False) None¶
Add items to the media gallery.
- Parameters:
item (
MediaGalleryItem|AttachmentComponent|File|Asset|str) – Items to add to the media galleryspoiler (
bool) – If the media should be marked as spoiler or not
- Return type:
- 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.
- async callback(ctx) BaseResponse | None¶
Called when the view is interacted with.
- Return type:
- Parameters:
ctx (Context)
- property loop: AbstractEventLoop¶
The event loop this storage is running in.
- 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 (
Iterable[Snowflake|int|str] |None) – Users that are allowed to interact with the view, as objects or IDs (int or a string of digits). Anyone else gets an ephemeral rejection.original_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|None) – How long it should take until the code simply times out. Set to None for the view to never time out on its own.
- Return type:
- Returns:
Returns the new context of the interaction, or None if timed out
- Raises:
If call_after is provided and is not a coroutine function - If users contains something that is not a user or an ID
- 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:
- 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: list[ComponentOption]¶
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)
- 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)
- async callback(ctx) BaseResponse | None¶
Called when the view is interacted with.
- Return type:
- Parameters:
ctx (Context)
- property loop: AbstractEventLoop¶
The event loop this storage is running in.
- 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 (
Iterable[Snowflake|int|str] |None) – Users that are allowed to interact with the view, as objects or IDs (int or a string of digits). Anyone else gets an ephemeral rejection.original_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|None) – How long it should take until the code simply times out. Set to None for the view to never time out on its own.
- Return type:
- Returns:
Returns the new context of the interaction, or None if timed out
- Raises:
If call_after is provided and is not a coroutine function - If users contains something that is not a user or an ID
- 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)