BaseBot

A subclass of discord.ext.commands.Bot. This bot implement some manage commands errors.

main.py
import discord
from discord_slash import SlashCommand
import baseDiscord

mybot = baseDiscord.BaseBot(
    token="my token",  # token of your bot
    prefix="!",  # prefix of your bot
    color=discord.Colour.blue(),  # color embed
    color_error=discord.Colour.red(),  # color embed for error message
    intents=discord.Intents.all()  # intents
)
slash = SlashCommand(bot, sync_commands=True)  # For slash commands

Parameters

BaseBot.__init__(self, token: str, *args, color: discord.Colour, color_error: discord.Colour, send_errors: bool = False, permissions: int = 0, logger=None, **kwargs)

Parameter

Type

Description

Required

Default

token

str

The Token of bot

✔️

*args

*Any

Positional arguments to passed to the constructor of discord.ext.commands.Bot

✔️

color

Union[discord.Colour, Tuple[R, G, B]]

The main color of Bot (for embeds).

✔️

color_error

Union[discord.Colour, Tuple[R, G, B]]

The color for errors messages (embeds)

✔️

send_errors

bool

If True, the bot send a error message to owner of application for all commands errors not manage

False

permissions

int

The permissions of Bot (use for invitation URL)

0

logger

logging.Logger

A logger to use in the application. If None, a default logger in debug level with the class name of bot is used.

None

**kwargs

**Any

Keywords arguments to passed to the constructor of discord.ext.commands.Bot

Attributes

Attributes of discord.ext.commands.Bot+

Name

Type

Description

token

str

The Token of bot

color

Union[discord.Colour, Tuple[R, G, B]]

The main color of Bot (for embeds).

color_error

Union[discord.Colour, Tuple[R, G, B]]

The color for errors messages (embeds)

send_errors

bool

If True, the bot send a error message to owner of application for all commands errors not manage

permissions

int

The permissions of Bot (use for invitation URL)

logger

logging.Logger

A logger to use in the application.

app_info

AppInfo instance loaded in on_readyevent

avatar_url

str

Avatar URL of bot loaded in on_readyevent

Methods

Methods of discord.ext.commands.Bot+

  • messages_on_ready : messages to display on an on_ready event.

    • Default: display informations on bot (name and id)

  • async init_on_ready : asynchrone method to initialize attributes on an on_ready event.

    • Default: initialize app_info and avatar_url attributes

  • get_invitation : method to get invitation URL with permissions define by permissions attribute

    • Parameters

      • permissions : int = None : permission to use, if None, use the permissions attribute

    • Returns

      • invitation_url : str : The invitation URL of bot

Methods overwrite

async on_command_error : manage some commands errors :

Error

Do

commands.errors.CommandNotFound

Ignore this exception

commands.errors.BadArgument

Send an error message to user

MissingRequiredArgument

Send an error message to user

MissingPermissions

Send an error message to user with required permissions

MissingRoles

Send an error message to user with roles required

BotMissingPermissions

Send an error message to user with permissions required

BotMissingRole

Send an error message to user with roles required

Last updated