View

discord_http.view module

class discord_http.view.ActionRow(*components)

Bases: Item

Represents an action row component in a message, containing buttons, selects, and links.

Parameters:

components (Button | Select | Link)

components

The components contained within the action row

Type:

Button | Select | Link

add_item(item) None

Add an item to the action row.

Parameters:

item (Button | Select | Link) – The item to add to the action row

Return type:

None

classmethod from_dict(data) ActionRow

Returns an action row from a dict provided by Discord.

Return type:

ActionRow

Parameters:

data (dict)

remove_items(*, label=None, custom_id=None) int

Remove items from the action row.

Parameters:
  • label (str | None) – Label of the item

  • custom_id (str | None) – Custom ID of the item

Return type:

int

Returns:

Returns the amount of items removed

to_dict() dict

Returns a dict representation of the action row.

Return type:

dict

class discord_http.view.AttachmentComponent(*, state, data)

Bases: object

Represents an attachment component.

Parameters:
url

The URL of the attachment

Type:

str

description

The description of the attachment, if any

Type:

str | None

spoiler

Whether the attachment is a spoiler or not

Type:

bool

filename

The filename of the attachment, if any

Type:

str | None

size

The size of the attachment in bytes

Type:

int

height

The height of the attachment, if any

Type:

int | None

width

The width of the attachment, if any

Type:

int | None

placeholder

The placeholder of the attachment, if any

Type:

str | None

placeholder_version

The placeholder version of the attachment, if any

Type:

int | None

content_type

The content type of the attachment, if any

Type:

str | None

flags

The flags of the attachment, if any

Type:

int

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:

bytes

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.

Parameters:
  • path (str) – Path to save the file to, which includes the filename and extension. Example: ./path/to/file.png

  • use_cached (bool) – Whether to use the cached URL or not, defaults to False

Return type:

int

Returns:

The amount of bytes written to the file

to_dict() dict

The attachment as a dictionary.

Return type:

dict

async to_file(*, filename, spoiler=False) File

Convert the attachment to a sendable File object for Message.send().

Parameters:
  • filename (str) – Filename for the file, if empty, the attachment’s filename will be used

  • spoiler (bool) – Weather the file should be marked as a spoiler or not, defaults to False

Return type:

File

Returns:

The attachment as a File object

class discord_http.view.Button(*, label=None, style=ButtonStyles.primary, disabled=False, custom_id=None, sku_id=None, emoji=None, url=None)

Bases: Item

Represents a button component in a message.

Parameters:
label

The label of the button

Type:

str | None

style

The style of the button

Type:

ButtonStyles | str | int

disabled

Whether the button is disabled or not

Type:

bool

custom_id

The custom ID of the button

Type:

str | None

sku_id

The SKU ID of the button, only required for premium buttons

Type:

“Snowflake | int | None”

emoji

The emoji associated with the button

Type:

str | dict | None

url

The URL of the button, only required for link buttons

Type:

str | None

to_dict() dict

Returns a dict representation of the button.

Return type:

dict

class discord_http.view.ChannelSelect(*channels, placeholder=None, custom_id=None, min_values=1, max_values=1, default_values=None, disabled=False, label=None, description=None, required=False)

Bases: Select

Represents a channel select menu component in a message.

Parameters:
placeholder

The placeholder text for the channel select menu

Type:

str | None

custom_id

The custom ID of the channel select menu

Type:

str | None

min_values

The minimum number of values that can be selected

Type:

int | None

max_values

The maximum number of values that can be selected

Type:

int | None

default_values

The default selected values for the channel select menu

Type:

list[“BaseChannel | int”] | None

disabled

Whether the channel select menu is disabled or not

Type:

bool

label

The label of the select menu (only works for modals)

Type:

str | None

description

The description of the select menu (only works for modals)

Type:

str | None

required

Whether the select menu is required or not (only works for modals)

Type:

bool | None

to_dict() dict

Returns a dict representation of the channel select menu.

Return type:

dict

class discord_http.view.ContainerComponent(*items, colour=None, spoiler=None)

Bases: Item

Represents a container component in a message.

Parameters:
items

The items contained within the container

Type:

Item

colour

The colour of the container, can be a Colour object or an integer

Type:

Colour | int | None

spoiler

Whether the container is marked as a spoiler

Type:

bool | None

add_item(item) Item

Add an item to the container component.

Parameters:

item (Item) – The item to add to the container component

Return type:

Item

Returns:

Returns the item that was added

remove_index(index) Item | None

Remove an item from the container component.

Parameters:

index (int) – The index of the item to remove

Return type:

Item | None

Returns:

Returns whether the item was removed

to_dict() dict

Returns a dict representation of the container component.

Return type:

dict

class discord_http.view.FileComponent(file, *, spoiler=False)

Bases: Item

Represents a file component in a message.

Parameters:
file

The file to be sent

Type:

Asset | AttachmentComponent | str

spoiler

Whether the file is a spoiler

Type:

bool

to_dict() dict

Returns a dict representation of the file component.

Return type:

dict

class discord_http.view.Item(*, type)

Bases: object

Base class for all components in discord.http API.

Parameters:

type (ComponentType)

to_dict() dict

Returns a dict representation of the item.

Return type:

dict

Bases: Button

Button alias for the link style.

Parameters:
  • url (str)

  • label (str | None)

  • emoji (str | None)

  • disabled (bool)

url

URL to open when the button is clicked

label

Label of the button

emoji

Emoji shown on the left side of the button

disabled

Whether the button is disabled or not

class discord_http.view.MediaGalleryComponent(*items)

Bases: Item

Represents a media gallery component in a message.

Parameters:

items (MediaGalleryItem | File | Asset | str)

items

The items contained within the media gallery

Type:

MediaGalleryItem | File | Asset | str

add_item(item) None

Add items to the media gallery.

Parameters:

item (MediaGalleryItem | File | Asset | str) – Items to add to the media gallery

Return type:

None

to_dict() dict

Returns a dict representation of the media gallery component.

Return type:

dict

class discord_http.view.MediaGalleryItem(url, *, description=None, spoiler=False)

Bases: object

Represents an item in a media gallery.

Parameters:
url

The URL of the media item, can be a file, asset, attachment component, or a string URL

Type:

File | Asset | AttachmentComponent | str

description

The description of the media item

Type:

str | None

spoiler

Whether the media item is marked as a spoiler

Type:

bool

to_dict() dict

Returns a dict representation of the media gallery item.

Return type:

dict

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: Select

Represents a mentionable select menu component in a message.

Parameters:
  • placeholder (str | None)

  • custom_id (str | None)

  • min_values (int | None)

  • max_values (int | None)

  • default_values (list[Member | Role | int] | None)

  • disabled (bool)

  • label (str | None)

  • description (str | None)

  • required (bool)

placeholder

The placeholder text for the mentionable select menu

Type:

str | None

custom_id

The custom ID of the mentionable select menu

Type:

str | None

min_values

The minimum number of values that can be selected

Type:

int | None

max_values

The maximum number of values that can be selected

Type:

int | None

default_values

The default selected values for the mentionable select menu

Type:

list[“Member | Role | int”] | None

disabled

Whether the mentionable select menu is disabled or not

Type:

bool

label

The label of the select menu (only works for modals)

Type:

str | None

description

The description of the select menu (only works for modals)

Type:

str | None

required

Whether the select menu is required or not (only works for modals)

Type:

bool | None

class discord_http.view.Modal(*, title, custom_id=None)

Bases: InteractionStorage

Represents a modal component in a message.

Parameters:
  • title (str)

  • custom_id (str | None)

title

The title of the modal

Type:

str

custom_id

The custom ID of the modal

Type:

str | None

add_item(component, *, label=None, description=None) LabelComponent | TextDisplayComponent

Add an item to the modal.

Parameters:
  • component (TextDisplayComponent | TextInputComponent | Select) – The component to add to the modal

  • label (str | None) – The label of the component, overwrites component.label

  • description (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

to_dict() dict

Returns a dict representation of the modal.

Return type:

dict

class discord_http.view.Premium(sku_id)

Bases: Button

Button alias for the premium SKU style.

Parameters:

sku_id (Snowflake | int)

sku_id

SKU ID of the premium button

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: Select

Represents a role select menu component in a message.

Parameters:
  • placeholder (str | None)

  • custom_id (str | None)

  • min_values (int | None)

  • max_values (int | None)

  • default_values (list[Role | int] | None)

  • disabled (bool)

  • label (str | None)

  • description (str | None)

  • required (bool)

placeholder

The placeholder text for the role select menu

Type:

str | None

custom_id

The custom ID of the role select menu

Type:

str | None

min_values

The minimum number of values that can be selected

Type:

int | None

max_values

The maximum number of values that can be selected

Type:

int | None

default_values

The default selected values for the role select menu

Type:

list[“Role | int”] | None

disabled

Whether the role select menu is disabled or not

Type:

bool

label

The label of the select menu (only works for modals)

Type:

str | None

description

The description of the select menu (only works for modals)

Type:

str | None

required

Whether the select menu is required or not (only works for modals)

Type:

bool | None

class discord_http.view.SectionComponent(*components, accessory)

Bases: Item

Represents a section component in a message.

Parameters:
components

The components contained within the section

Type:

TextDisplayComponent | str

accessory

The accessory component for the section

Type:

Button | ThumbnailComponent | AttachmentComponent | Asset | File | str

to_dict() dict

Returns a dict representation of the section component.

Return type:

dict

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: Item

Represents a select menu component in a message.

Parameters:
  • label (str | None)

  • description (str | None)

  • placeholder (str | None)

  • custom_id (str | None)

  • min_values (int | None)

  • max_values (int | None)

  • disabled (bool)

  • options (list[dict] | None)

  • required (bool | None)

  • _type (ComponentType | None)

label

The label of the select menu (only works for modals)

Type:

str | None

description

The description of the select menu (only works for modals)

Type:

str | None

placeholder

The placeholder text for the select menu

Type:

str | None

custom_id

The custom ID of the select menu

Type:

str | None

min_values

The minimum number of values that can be selected

Type:

int | None

max_values

The maximum number of values that can be selected

Type:

int | None

disabled

Whether the select menu is disabled or not

Type:

bool

options

The options for the select menu

Type:

list[dict] | None

required

Whether the select menu is required or not (only works for modals)

Type:

bool | None

add_item(*, label, value, description=None, emoji=None, default=False) None

Add an item to the select menu.

Parameters:
  • label (str) – Label of the item

  • value (str) – The value of the item, which will be shown on interaction response

  • description (str | None) – Description of the item

  • emoji (str | None) – Emoji shown on the left side of the item

  • default (bool) – Whether the item is selected by default

Raises:

ValueError – If there are more than 25 options

Return type:

None

to_dict() dict

Returns a dict representation of the select menu.

Return type:

dict

class discord_http.view.SeparatorComponent(*, spacing=None, divider=None)

Bases: Item

Represents a separator component in a message.

Parameters:
spacing

The spacing type of the separator

Type:

SeparatorSpacingType | None

divider

Whether the separator is a divider or not

Type:

bool | None

to_dict() dict

Returns a dict representation of the separator.

Return type:

dict

class discord_http.view.TextDisplayComponent(content)

Bases: Item

Represents a text display component in a message.

Parameters:

content (str)

content

The content of the text display component

Type:

str

to_dict() dict

Returns a dict representation of the text display.

Return type:

dict

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: Item

Represents a text input component in a modal.

Parameters:
  • label (str | None)

  • description (str | None)

  • custom_id (str | None)

  • style (TextStyles | None)

  • placeholder (str | None)

  • min_length (int | None)

  • max_length (int | None)

  • default (str | None)

  • required (bool)

label

The label of the text input

Type:

str | None

description

The description of the text input

Type:

str | None

custom_id

The custom ID of the text input

Type:

str | None

style

The style of the text input

Type:

TextStyles | None

placeholder

The placeholder text of the text input

Type:

str | None

min_length

The minimum length of the text input

Type:

int | None

max_length

The maximum length of the text input

Type:

int | None

default

The default value of the text input

Type:

str | None

required

Whether the text input is required or not

Type:

bool

to_dict() dict

Returns a dict representation of the modal item.

Return type:

dict

class discord_http.view.ThumbnailComponent(url, *, description=None, spoiler=False)

Bases: Item

Represents a thumbnail component in a message.

Parameters:
url

The URL of the thumbnail image

Type:

Asset | AttachmentComponent | str

description

The description of the thumbnail

Type:

str | None

to_dict() dict

Returns a dict representation of the thumbnail.

Return type:

dict

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: Select

Represents a user select menu component in a message.

Parameters:
  • placeholder (str | None)

  • custom_id (str | None)

  • min_values (int | None)

  • max_values (int | None)

  • default_values (list[Member | int] | None)

  • disabled (bool)

  • label (str | None)

  • description (str | None)

  • required (bool)

placeholder

The placeholder text for the user select menu

Type:

str | None

custom_id

The custom ID of the user select menu

Type:

str | None

min_values

The minimum number of values that can be selected

Type:

int | None

max_values

The maximum number of values that can be selected

Type:

int | None

default_values

The default selected values for the user select menu

Type:

list[“Member | int”] | None

disabled

Whether the user select menu is disabled or not

Type:

bool

label

The label of the select menu (only works for modals)

Type:

str | None

description

The description of the select menu (only works for modals)

Type:

str | None

required

Whether the select menu is required or not (only works for modals)

Type:

bool | None

class discord_http.view.View(*items)

Bases: InteractionStorage

Represents a view component in a message.

Parameters:

items (Item)

items

The items contained within the view, can be buttons, selects, links, etc.

Type:

Item

add_item(item) Item

Add an item to the view.

Parameters:

item (Item) – The item to add to the view

Return type:

Item

Returns:

Returns the added item

classmethod from_dict(*, state, data) View

Returns a view from a dict provided by Discord.

Return type:

View

Parameters:
get_item(*, label=None, custom_id=None) Item | None

Get an item from the view that matches the parameters.

Parameters:
  • label (str | None) – Label of the item

  • custom_id (str | None) – Custom ID of the item

Return type:

Item | None

Returns:

Returns the item if found, otherwise None

remove_items(*, label=None, custom_id=None) int

Remove items from the view that match the parameters.

Parameters:
  • label (str | None) – Label of the item

  • custom_id (str | None) – Custom ID of the item

Return type:

int

Returns:

Returns the amount of items removed

to_dict() list[dict]

Returns a dict representation of the view.

Return type:

list[dict]