Components

Classes that are adding some functionality for default components.

Note

If you want to register global checks and error handlers, all Views must inherit from EzView instead of discord.ui.View.

from ezcord import View

class MyView(View):  # right
    ...

class MyView(discord.ui.View):  # wrong
    ...
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!")

@ezcord.event
async def on_view_error(error, item, interaction):
    await interaction.response.send_message("Something went wrong!")

@ezcord.event
async def on_modal_error(error, interaction):
    await interaction.response.send_message("Something went wrong!")
class ezcord.components.View(*args, **kwargs)[source]

This class extends from discord.ui.View and adds some functionality.

async on_error(error, item, interaction)[source]

Sends an error message to a webhook, if the URL was passed in Bot.

Executes all registered error handlers with the @ezcord.event decorator.

Return type:

None

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.Modal(*args, **kwargs)[source]

This class extends from discord.ui.Modal and adds an error handler.

async on_error(error, interaction)[source]

Sends an error message to a webhook, if the webhook URL was passed into Bot.

Executes all registered error handlers with the @ezcord.event decorator.

Return type:

None

ezcord.components.EzModal

alias of Modal

ezcord.components.EzView

alias of View