Bot

class ezcord.bot.Bot(intents=<Intents value=3243773>, *, debug=True, error_handler=True, error_webhook_url=None, ignored_errors=None, full_error_traceback=False, language='auto', default_language='en', ready_event=ReadyEvent.table, **kwargs)[source]

The EzCord bot class. This is a subclass of discord.Bot if you use Pycord.

Hint

As this class extends from discord.Bot, only slash commands are supported. If you want to use prefix commands with Pycord, use PrefixBot instead.

If you use Discord.py, you can use this class for both slash and prefix commands.

Parameters:
  • intents (Intents) – The intents to use for the bot. Defaults to discord.Intents.default().

  • debug (bool) – Enable log messages. Defaults to True.

  • error_handler (bool) – Enable the error handler. Defaults to True.

  • error_webhook_url (str | None) –

    The webhook URL to send error messages to. Defaults to None.

    Note

    You can disable the default error handler, but still provide an error webhook URL. This will send an error report to the webhook, but it won’t send an error message to the user.

  • ignored_errors (list[Any] | None) – A list of error types to ignore. Defaults to None.

  • full_error_traceback (bool) – Whether to send the full error traceback. If this is False, only the most recent traceback will be sent. Defaults to False.

  • language (str) – The language to use for user output. If this is set to auto, the bot will use the language of the interaction locale whenever possible.

  • default_language (str) – The default language to use if the interaction locale is not available. Defaults to "en". en and de are available by default, but you can add your own language as described in the language example.

  • ready_event (ReadyEvent | None) – The style for on_ready_event(). Defaults to ReadyEvent.default. If this is None, the event will be disabled.

  • **kwargs – Additional keyword arguments for discord.Bot.

property cmd_count: int

The number of loaded application commands, including subcommands.

async get_application_context(interaction, cls=<class 'ezcord.emb.EzContext'>)[source]

A custom application command context for Pycord.

load_cogs(*directories, subdirectories=False, ignored_cogs=None, log=CogLog.sum, custom_log_level='COG', log_color=None)[source]

Load all cogs in the given directories.

Parameters:
  • *directories (str) – Names of the directories to load cogs from. Defaults to "cogs".

  • subdirectories (bool) – Whether to load cogs from subdirectories. Defaults to False.

  • ignored_cogs (list[str] | None) – A list of cogs to ignore. Defaults to None.

  • log (CogLog | str | None) – The log format for cogs. Defaults to CogLog.default. If this is None, logs will be disabled.

  • custom_log_level (str | None) – The name of the custom log level for cogs. Defaults to COG.

  • log_color (str | None) – The color to use for cog logs. This will only have an effect if custom_log_level is enabled. If this is None, a default color will be used.

add_ready_info(name, value, position=None, color=None)[source]

Adds an information to the on_ready message.

Parameters:
  • name (str) – The name of the info to add. If this name already exists, the info will be updated.

  • value (str | int) – The value of the info.

  • position (int | None) – The position of the info. If this is None, the info will be added at the end.

  • color (str | None) – The color of the info. If this is None, a default color will be used.

remove_ready_info(*elements)[source]

Removes an information from the on_ready message.

Parameters:

*elements (str | int) – The names or positions of the infos to remove.

ready(*, title='Bot is online with EzCord 0.6.4', style=ReadyEvent.table, default_info=True, new_info=None, colors=None)[source]

Print a custom ready message.

Parameters:
  • title (str) – The title of the ready message.

  • style (ReadyEvent) – The style of the ready message. Defaults to ReadyEvent.default.

  • default_info (bool) – Whether to include the default information. Defaults to True.

  • new_info (dict | None) –

    A dictionary of additional information to include in the ready message. Defaults to None.

    Note

    Information can also be added with add_ready_info() and removed with remove_ready_info().

  • colors (list[str] | None) –

    A list of colors to use for the ready message. If no colors are given, default colors will be used.

    Colors can only be used with ReadyEvent.box_colorful and all table styles.

async on_error(event_method, *args, **kwargs)[source]

This overrides the default on_error event to send an error webhook.

Return type:

None

get_cmd(name, bold=True)[source]

Helper method to get a command mention. Returns a string if the command was not found.

Parameters:
  • name (str) – The name of the command to get.

  • bold (bool) – Whether to bold the command name. Defaults to True.

Return type:

str

add_help_command(*, style=HelpStyle.embed_fields, embed=None, show_categories=True, show_description=True, show_cmd_count=False, timeout=None, ephemeral=True, author_only=True, guild_only=False, buttons=None, title_format='{emoji} - {name}', description_format='{description}', permission_check=False, **kwargs)[source]

Add a help command that uses a select menu to group commands by cogs.

If you use Cog, you can pass in emojis to use for the select menu.

Hint

Title and description can be formatted with the following placeholders:

  • {emoji} - The emoji of the cog.

  • {name} - The name of the cog.

  • {description} - The description of the cog.

Parameters:
  • style (HelpStyle) – The style to use for the help command. Defaults to HelpStyle.default.

  • embed (Embed | None) – The embed to use for the help command. If this is None, a default embed will be used. All template variables that are listed in ezcord.emb.set_embed_templates() can be used here.

  • show_categories (bool) – Whether to display the categories of the help command front page. Defaults to True.

  • show_description (bool) – Whether to display the description in each category page. Defaults to True.

  • show_cmd_count (bool) – Whether to display the command count of each category in the select menu. Defaults to False.

  • timeout (int | None) – The timeout for the select menu. Defaults to None.

  • ephemeral (bool) – Whether the help command should be ephemeral. Defaults to True.

  • author_only (bool) – Whether the help command should only be visible to the author. Defaults to True. This only works if ephemeral is False.

  • guild_only (bool) – Whether the help command should only be visible in guilds. Defaults to False.

  • buttons (list[Button] | None) – A list of buttons to add to the help command. Defaults to None.

  • title_format (str) – The title format of each category.

  • description_format (str) – The description format of each category.

  • permission_check (bool) – Whether to check for permissions before showing a command. Defaults to True.

  • **kwargs (Union[Callable, str]) – Additional variables to use in the help command. This can either be a string value or a callable that returns a string value.

add_status_changer(*activities, interval=60, status=('online', 'online'), shuffle=False, **kwargs)[source]

Add a status changer that changes the bot’s activity every interval seconds.

Note

You can use the following variables in status texts:

  • {guild_count} - The number of guilds the bot is in.

  • {user_count} - The number of users the bot can see.

  • {cmd_count} - The number of application commands.

You can create custom variables by passing in variable names and values as **kwargs.

Parameters:

Example

def get_coins():  # This can also be async
    return 69

bot.add_status_changer(
    [
        "{guild_count} Servers",  # Strings will be converted to CustomActivity
        discord.Game("with {coins} coins")
    ],
    coins=get_coins
)
add_blacklist(admin_server_ids, *, db_path='blacklist.db', db_name='blacklist', raise_error=False, owner_only=True, disabled_commands=None, **kwargs)[source]

Add a blacklist that bans users from using the bot. This should be called before the on_ready event.

Parameters:
  • admin_server_ids (list[int]) – A list of server IDs. Admins on these servers will be able to see the admin commands.

  • db_path (str) – The path to the database file.

  • db_name (str) – The name of the database.

  • raise_error (bool) –

    Whether to raise errors.Blacklisted error in case a blacklisted user uses the bot. If this is False, a default message will be sent to the user.

    Note

    This can be used to handle the error in your own error handler.

  • owner_only (bool) – Whether the blacklist can only be managed by the bot owner. Defaults to True.

  • disabled_commands (list[Literal['add', 'remove', 'show', 'owner', 'server', 'show_servers']] | None) – A list of command names to disable. Defaults to None.

  • **kwargs (Callable) – Overwrites for the default blacklist commands. This can be used to change the default commands behavior.

localize_commands(languages, default='en-US', cogs=True)[source]

Localize commands with the given test dictionary. This should be called after the commands have been added to the bot, but before they are synced.

A list of available languages is available here: https://discord.com/developers/docs/reference#locales

This is currently only supported for Pycord.

Parameters:
  • languages (dict[str, dict]) –

    A dictionary with command localizations. An example can be found in the localization example.

    If an en key is found, the values will be used for both en-GB and en-US.

  • default (str) – The default language to use for languages that are not in the dictionary. Defaults to en-US.

  • cogs (bool) – Whether to localize the cogs. Defaults to True.

async setup_hook()[source]

This is used for Discord.py startup and should not be called manually.

run(token=None, *, env_path='.env', token_var='TOKEN', **kwargs)[source]

This overrides the default discord.Bot.run() method and automatically loads the token from the environment.

Parameters:
  • token (str | None) – The bot token. If this is None, the token will be loaded from the environment.

  • env_path (str | PathLike[str] | None) – The path to the environment file. Defaults to .env. If this is None, environment variables are not loaded automatically.

  • token_var (str) – The name of the token variable in the environment file. Defaults to TOKEN.

  • **kwargs – Additional keyword arguments for discord.Bot.run().

Return type:

None

async start(token=None, *, env_path='.env', token_var='TOKEN', **kwargs)[source]

This overrides the default discord.Bot.start() method and automatically loads the token from the environment.

Parameters:
  • token (str | None) – The bot token. If this is None, the token will be loaded from the environment.

  • env_path (str | PathLike[str] | None) – The path to the environment file. Defaults to .env. If this is None, environment variables are not loaded automatically.

  • token_var (str) – The name of the token variable in the environment file. Defaults to TOKEN.

  • **kwargs – Additional keyword arguments for discord.Bot.start().

Return type:

None

class ezcord.bot.PrefixBot(*args, **kwargs)[source]

A subclass of discord.ext.commands.Bot that implements the Bot class.

This class can be used if you want to use EzCord with prefix commands. This is only needed for Pycord.

class ezcord.bot.BridgeBot(*args, **kwargs)[source]

A subclass of discord.ext.bridge.Bot that implements the Bot class.

This class can be used if you want to use EzCord with bridge commands. This is only needed for Pycord.

class ezcord.bot.AutoShardedBot(*args, **kwargs)[source]

A subclass of discord.AutoShardedBot that implements the Bot class.

This class can be used if you want to use EzCord with an auto-sharded bot.

class ezcord.bot.Cog(bot)[source]

This can be used as a base class for all cogs.

Parameters:

bot (Bot) – The bot instance.

emoji = None
group = None
hidden = False