Components

Classes that are adding some functionality for default components.

Hint

Components in your code are automatically replaced with the ones from this module. You can use discord.ui.View instead of ezcord.View.

ezcord.components.event(coro)[source]

A decorator to register custom checks and error handlers for Discord components.

Example

@ezcord.event
async def view_check(interaction):
    return interaction.user.id == 12345  # Returns True or False

@ezcord.event
async def on_view_check_failure(interaction):
    await interaction.response.send_message("You can't use this!")
class ezcord.components.Modal(*args, **kwargs)[source]

Base class for all discord.ui.Modal classes.

class ezcord.components.View(*args, ignore_timeout_error=False, **kwargs)[source]
ignore_timeout_errors: bool = False

Base class for all discord.ui.View classes that adds some functionality.

Parameters:

ignore_timeout_error – If True, views will not raise an exception if an error occurs during the timeout event.

async interaction_check(interaction)[source]

Returns True if all custom checks return True or if no custom checks are registered.

Return type:

bool

async on_check_failure(interaction)[source]

This method is called if interaction_check() returns False.

Return type:

None

async on_timeout()[source]

If disable_on_timeout is set to True, this will disable all components, unless the viw has been explicitly stopped.

Return type:

None

class ezcord.components.EzView(*args, ignore_timeout_error=False, **kwargs)[source]

Alias for View.

class ezcord.components.EzModal(*args, **kwargs)[source]

Alias for Modal.

class ezcord.components.DropdownPaginator(options, next_page_label='Next page', previous_page_label='Previous page', next_page_emoji='⬇️', previous_page_emoji='⬆️', page=0, **kwargs)[source]

A dropdown paginator that can be used to paginate through a list of options.

This is useful when we have more options than Discord allows in a single dropdown menu.

Parameters:
  • options (list[SelectOption]) – The options that will be displayed in the dropdown.

  • next_page_label (str) – The label of the next page button.

  • previous_page_label (str) – The label of the previous page button.

  • next_page_emoji (str) – The emoji of the next page button.

  • previous_page_emoji (str) – The emoji of the previous page button.

  • page (int) – The current page of the dropdown.

  • **kwargs – Additional keyword arguments that are passed to discord.ui.Select.

property item_selected

Returns True if the user selected an item from the dropdown. If the user clicked on the next or previous page button, this will return False.

async callback(interaction)[source]

Edit the dropdown menu if the user selects a page option.

check_next_page()[source]

Returns True if the user clicked on the next page button. In this case, the dropdown menu will be edited.

Return type:

bool

check_previous_page()[source]

Returns True if the user clicked on the previous page button. In this case, the dropdown menu will be edited.

Return type:

bool

load_options(options, chunk=0)[source]

Split the options into chunks and append options for next/previous pages.

Return type:

list[SelectOption]