Bot - LeConstellationniste/Discord.py-Framework- GitHub Wiki
Basic use of the bot class :
import asyncio
import discord
from discordEasy import Bot
token = "yourToken"
prefix = ">"
bot = Bot(prefix=prefix, token=token, description="A bot exemple.") # A instance of Bot is created
... # Add Commands, Listeners and CommmandSet here.
bot.run() # the bot is started
A base class for the class Bot
. It's a subclass of discord.Client
.
Attribute Name | Type | Description | Default value |
---|---|---|---|
prefix |
str | The prefix of bot to call a command in Discord | |
token |
str | The Discord Bot token. | |
description |
str | The description for the bot. Use in the help default command | "" |
colour |
discord.Colour | The color of bot. It's the color use for normal embeds. | discord.Colour.blue() |
coulour_error |
discord.Colour | The color for embeds of error messages. | discord.Coulour.red() |
avatar_url |
str | Avatar url of bot. A shortcut to client.user.avatar_url . |
Initialize with the event on_ready
|
app_info |
discord.AppInfo | The discord.AppInfo instance. |
Initialize with the event on_ready
|
-
-
Description: A routine use when a error in a command is raised.
- If error is a
errors.MissingArgumentsError
, the routineon_missing_arguments
is called. - If error is a
errors.DiscordTypeError
, the routineon_type_error
is called. - If error is a
errors.ConditionError
, the routineon_condition_error
is called. - If error is a
discord.Forbidden
, the routineon_permission_error
is called. - Else, a
Logs.error
is display witherror.message
and the traceback.
- If error is a
-
Arguments:
-
error
: Exception - The error raise. -
message
: discord.Message - The Discord message which raised the error.
-
-
-
-
Description: A routine use when a error in a listener is raised. A
Logs.error
is display witherror.message
and the traceback. -
Arguments:
-
error
: Exception - The error raise.
-
-
-
-
Description: A routine which send a error message, for a missing of argument, in
channel
. -
Arguments:
-
channel
: discord.TextChannel or discord.DMChannel - The channel where the command was called.
-
-
-
-
Description: A routine which send a error message, for a type error, in
channel
. -
Arguments:
-
channel
: discord.TextChannel or discord.DMChannel - The channel where the command was called. -
types
: list[type] - types of arguments ask in the command (Command.types_options
)
-
-
-
-
Description: A routine which send a error message, for a forbidden error (the bot have not the permission), in
channel
. -
Arguments:
-
channel
: discord.TextChannel or discord.DMChannel - The channel where the command was called.
-
-
-
-
Description: A routine which send a error message, for a permission error (the user have not permission), in
channel
. -
Arguments:
-
channel
: discord.TextChannel or discord.DMChannel - The channel where the command was called.
-
-
-
-
Description: A routine which send a error message, for a condition error (when checks functions pass in command return
False
), inchannel
. -
Arguments:
-
channel
: discord.TextChannel or discord.DMChannel - The channel where the command was called.
-
-
-
-
Description: a method to launch the bot, it's the
Clent.run
method overwritte. -
Arguments: This method hasn't argument.
-
The Bot class to use. It's a subclass of BaseBot
.
Attribute Name | Type | Description | Default value |
---|---|---|---|
prefix |
str | The prefix of bot to call a command in Discord | |
token |
str | The Discord Bot token. | |
avatar_url |
str | Avatar url of bot. A shortcut to client.user.avatar_url . |
Initialize with the event on_ready
|
description |
str | The description for the bot. Use in the help default command | "" |
colour |
discord.Colour | The color of bot. It's the color use for normal embeds. | discord.Colour.blue() |
coulour_error |
discord.Colour | The color for embeds of error messages. | discord.Coulour.red() |
app_info |
discord.AppInfo | The discord.AppInfo instance. |
Initialize with the event on_ready
|
send_errors |
bool | If True , the errors raised are send to the owner of application (self.app_info.owner ). |
False |
print_traceback |
bool | If True , all traceback are displayed in console logs. |
True |
sep_args |
str | The separator of arguments in a command, use to extract arguments of a Discord message. | " " |
commands |
list[Command] | The list of commands of bot. | [] |
listeners |
list[Listener] | The list of listeners of bot. | [] |
list_set |
list[CommandSet] | The list of commands set of bot. | [] |
-
-
Description: A routine which send a error message to owner of application when a error was raised.
-
Arguments:
-
error
: Exception - The error raised. -
traceback_msg
: str - the traceback message. -
where
: str - the function name where the error was raised.
-
-
-
Description: A routine use when a error in a command is raised.
- If error is a
errors.MissingArgumentsError
, the routineon_missing_arguments
is called. - If error is a
errors.DiscordTypeError
, the routineon_type_error
is called. - If error is a
errors.ConditionError
, the routineon_condition_error
is called. - If error is a
discord.Forbidden
, the routineon_permission_error
is called. - Else, a
Logs.error
is display witherror.message
. Ifself.print_traceback
isTrue
, the traceback is also displayed and ifself.send_errors
isTrue
,send_error_to_owner
is called.
- If error is a
-
Arguments:
-
error
: Exception - The error raise. -
message
: discord.Message - The Discord message which raised the error.
-
-
-
Description: A routine use when a error in a listener is raised. A
Logs.error
is display witherror.message
. Ifself.print_traceback
isTrue
, the traceback is also displayed and ifself.send_errors
isTrue
,send_error_to_owner
is called. -
Arguments:
-
error
: Exception - The error raise.
-
-
-
-
Description: a method to add a command to the bot.
-
Arguments:
-
command
: Command or function - The command or function to add to the bot. If it's afunction
, a Command instance is created with this function. -
checks
: list[function] - A list of function which return a boolean to check if the command can be execute or not. Use only ifcommand
argument is afunction
. -
admin
: bool - IfTrue
the command is aCommandAdmin
instance. Use only ifcommand
argument is afunction
. -
super_admin
: bool - IfTrue
the command is aCommandSuperAdmin
instance. Use only ifcommand
argument is afunction
. -
white_list
: list[int] - The list ofUser.id
which can use the command. Use only ifcommand
argument is afunction
and ifsuper_admin
argument isTrue
.
-
-
-
-
Description: a method to add a listener to the bot.
-
Arguments:
-
listener
: Listener or function - The listener to add to the bot. If it's afunction
, a Listener instance is created with this function. -
event_name
: str - the event name wich call the listener. Use only iflistener
argument is afunction
. -
checks
: list[function] - A list of function which return a boolean to check if the listener can be execute or not. Use only iflistener
argument is afunction
.
-
-
-
-
Description: a method to add several command to the bot.
-
Arguments:
-
commands
: list or dict or CommandSet - The list, dict of commands and functions, to add or a CommandSet to add. Several possible uses :- If
commands
is a list: the values can be a function, a command. - If
commands
is a dict: the keys are the names of commands and the values is the function. - If
commands
is a CommandSet, the other arguments are not used and the CommandSet is add toBot.list_set
.
- If
-
checks
: list[function] - the list of check functions, applied to all functions pass incommands
argument (but not to Commands). -
admin
: bool - IfTrue
, all functions incommands
are admin commands (but not to Commands). -
super_admin
: bool - IfTrue
, all functions incommands
are SuperAdmin commands (but not to Commands). -
white_list
: list[int] - The list of user id to add in the white list. Only use ifsuper_admin
isTrue
.
-
-
-
Description: a method to add several listener to the bot.
-
Arguments:
-
listeners
: list or dict - A list of Listener or of routine, or a dictionnary with the event name in key and the routine in value. - OPTIONNAL[
checks
]: list[function], default[]
- The list of check to execute listeners.
-
-