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 withPycord
, usePrefixBot
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 todiscord.Intents.default()
.debug (
bool
) – Enable log messages. Defaults toTrue
.error_handler (
bool
) – Enable the error handler. Defaults toTrue
.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 toNone
.full_error_traceback (
bool
) – Whether to send the full error traceback. If this isFalse
, only the most recent traceback will be sent. Defaults toFalse
.language (
str
) – The language to use for user output. If this is set toauto
, 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
andde
are available by default, but you can add your own language as described in the language example.ready_event (
ReadyEvent
|None
) – The style foron_ready_event()
. Defaults toReadyEvent.default
. If this isNone
, the event will be disabled.**kwargs – Additional keyword arguments for
discord.Bot
.
- 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 toFalse
.ignored_cogs (
list
[str
] |None
) – A list of cogs to ignore. Defaults toNone
.log (
CogLog
|str
|None
) – The log format for cogs. Defaults toCogLog.default
. If this isNone
, logs will be disabled.custom_log_level (
str
|None
) – The name of the custom log level for cogs. Defaults toCOG
.log_color (
str
|None
) – The color to use for cog logs. This will only have an effect ifcustom_log_level
is enabled. If this isNone
, 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:
- 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 toReadyEvent.default
.default_info (
bool
) – Whether to include the default information. Defaults toTrue
.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 withremove_ready_info()
.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:
- get_cmd(name, bold=True)[source]¶
Helper method to get a command mention. Returns a string if the command was not found.
- 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 toHelpStyle.default
.embed (
Embed
|None
) – The embed to use for the help command. If this isNone
, a default embed will be used. All template variables that are listed inezcord.emb.set_embed_templates()
can be used here.show_categories (
bool
) – Whether to display the categories of the help command front page. Defaults toTrue
.show_description (
bool
) – Whether to display the description in each category page. Defaults toTrue
.show_cmd_count (
bool
) – Whether to display the command count of each category in the select menu. Defaults toFalse
.timeout (
int
|None
) – The timeout for the select menu. Defaults toNone
.ephemeral (
bool
) – Whether the help command should be ephemeral. Defaults toTrue
.author_only (
bool
) – Whether the help command should only be visible to the author. Defaults toTrue
. This only works ifephemeral
isFalse
.guild_only (
bool
) – Whether the help command should only be visible in guilds. Defaults toFalse
.buttons (
list
[Button
] |None
) – A list of buttons to add to the help command. Defaults toNone
.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 toTrue
.**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:
activities (
str
|Activity
|Game
|Streaming
|CustomActivity
|list
[str
|Activity
|CustomActivity
|Game
|Streaming
]) – Activities to use for the status. Strings will be converted todiscord.CustomActivity
.interval (
int
) – The interval in seconds to change the status. Defaults to60
.status (
Status
) – The status to use. Defaults todiscord.Status.online
.shuffle (
bool
) – Whether to use a random order for the activities. Defaults toFalse
.**kwargs (
Union
[Callable
,str
]) – Additional variables to use in status texts. This can either be a string value or a callable that returns a string value.
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 isFalse
, 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 toTrue
.disabled_commands (
list
[Literal
['add'
,'remove'
,'show'
,'owner'
,'server'
,'show_servers'
]] |None
) – A list of command names to disable. Defaults toNone
.**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:
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 bothen-GB
anden-US
.default (
str
) – The default language to use for languages that are not in the dictionary. Defaults toen-US
.cogs (
bool
) – Whether to localize the cogs. Defaults toTrue
.
- 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 isNone
, 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 isNone
, environment variables are not loaded automatically.token_var (
str
) – The name of the token variable in the environment file. Defaults toTOKEN
.**kwargs – Additional keyword arguments for
discord.Bot.run()
.
- Return type:
- 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 isNone
, 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 isNone
, environment variables are not loaded automatically.token_var (
str
) – The name of the token variable in the environment file. Defaults toTOKEN
.**kwargs – Additional keyword arguments for
discord.Bot.start()
.
- Return type:
- class ezcord.bot.PrefixBot(*args, **kwargs)[source]¶
A subclass of
discord.ext.commands.Bot
that implements theBot
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 theBot
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 theBot
class.This class can be used if you want to use EzCord with an auto-sharded bot.