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 startedA 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_argumentsis called. - If error is a
errors.DiscordTypeError, the routineon_type_erroris called. - If error is a
errors.ConditionError, the routineon_condition_erroris called. - If error is a
discord.Forbidden, the routineon_permission_erroris called. - Else, a
Logs.erroris display witherror.messageand 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.erroris display witherror.messageand 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.runmethod 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_argumentsis called. - If error is a
errors.DiscordTypeError, the routineon_type_erroris called. - If error is a
errors.ConditionError, the routineon_condition_erroris called. - If error is a
discord.Forbidden, the routineon_permission_erroris called. - Else, a
Logs.erroris display witherror.message. Ifself.print_tracebackisTrue, the traceback is also displayed and ifself.send_errorsisTrue,send_error_to_owneris 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.erroris display witherror.message. Ifself.print_tracebackisTrue, the traceback is also displayed and ifself.send_errorsisTrue,send_error_to_owneris 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 ifcommandargument is afunction. -
admin: bool - IfTruethe command is aCommandAdmininstance. Use only ifcommandargument is afunction. -
super_admin: bool - IfTruethe command is aCommandSuperAdmininstance. Use only ifcommandargument is afunction. -
white_list: list[int] - The list ofUser.idwhich can use the command. Use only ifcommandargument is afunctionand ifsuper_adminargument 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 iflistenerargument 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 iflistenerargument 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
commandsis a list: the values can be a function, a command. - If
commandsis a dict: the keys are the names of commands and the values is the function. - If
commandsis 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 incommandsargument (but not to Commands). -
admin: bool - IfTrue, all functions incommandsare admin commands (but not to Commands). -
super_admin: bool - IfTrue, all functions incommandsare SuperAdmin commands (but not to Commands). -
white_list: list[int] - The list of user id to add in the white list. Only use ifsuper_adminisTrue.
-
-
-
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.
-
-