Bot - LeConstellationniste/Discord.py-Framework- GitHub Wiki

Bot

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

Class BaseBot

A base class for the class Bot. It's a subclass of discord.Client.

Attributes

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

Methods

  • on_command_error

  • on_discord_event_error

    • Description: A routine use when a error in a listener is raised. A Logs.error is display with error.message and the traceback.

    • Arguments:

      • error: Exception - The error raise.
  • on_missing_arguments

    • 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.
  • on_type_error

    • 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)
  • on_forbidden_error

    • 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.
  • on_permission_error

    • Description: A routine which send a error message, for a permission error (the user have not permission), in channel.

    • Arguments:

  • on_condition_error

    • Description: A routine which send a error message, for a condition error (when checks functions pass in command return False), in channel.

    • Arguments:

      • channel: discord.TextChannel or discord.DMChannel - The channel where the command was called.
  • run

    • Description: a method to launch the bot, it's the Clent.run method overwritte.

    • Arguments: This method hasn't argument.

Class Bot

The Bot class to use. It's a subclass of BaseBot.

Attributes

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. []

Methods

  • send_error_to_owner

    • 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.
  • on_command_error

  • Description: A routine use when a error in a command is raised.

  • Arguments:

    • error: Exception - The error raise.
    • message: discord.Message - The Discord message which raised the error.
  • on_discord_event_error

    • Description: A routine use when a error in a listener is raised. A Logs.error is display with error.message. If self.print_traceback is True, the traceback is also displayed and if self.send_errors is True, send_error_to_owner is called.

    • Arguments:

      • error: Exception - The error raise.
  • add_command

    • 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 a function, 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 if command argument is a function.
      • admin: bool - If True the command is a CommandAdmin instance. Use only if command argument is a function.
      • super_admin: bool - If True the command is a CommandSuperAdmin instance. Use only if command argument is a function.
      • white_list: list[int] - The list of User.id which can use the command. Use only if command argument is a function and if super_admin argument is True.
  • add_listener

    • 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 a function, a Listener instance is created with this function.
      • event_name: str - the event name wich call the listener. Use only if listener argument is a function.
      • checks: list[function] - A list of function which return a boolean to check if the listener can be execute or not. Use only if listener argument is a function.
  • add_commands

    • 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 to Bot.list_set.
    • checks: list[function] - the list of check functions, applied to all functions pass in commands argument (but not to Commands).

    • admin: bool - If True, all functions in commands are admin commands (but not to Commands).

    • super_admin: bool - If True, all functions in commands are SuperAdmin commands (but not to Commands).

    • white_list: list[int] - The list of user id to add in the white list. Only use if super_admin is True.

  • add_listeners

    • 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.
⚠️ **GitHub.com Fallback** ⚠️