# BaseBot

{% code title="main.py" %}

```python
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
```

{% endcode %}

### Parameters

```python
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](https://discord.com/developers/applications) of bot                                                                                          |    ✔️    |         |
| `*args`       |                  *\*Any*                  | Positional arguments to passed to the constructor of [`discord.ext.commands.Bot`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#bots) |    ✔️    |         |
| `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](https://discordapi.com/permissions.html) 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`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#bots)   |     ❌    |         |

### Attributes

Attributes of [`discord.ext.commands.Bot`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#bots)`+`

| Name         |                                        Type                                       | Description                                                                                                        |
| ------------ | :-------------------------------------------------------------------------------: | ------------------------------------------------------------------------------------------------------------------ |
| token        |                                       *str*                                       | The [Token](https://discord.com/developers/applications) 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](https://discordapi.com/permissions.html) of Bot (use for invitation URL)                         |
| logger       |                                  *logging.Logger*                                 | A logger to use in the application.                                                                                |
| app\_info    | [*AppInfo*](https://discordpy.readthedocs.io/en/latest/api.html#application-info) | [AppInfo](https://discordpy.readthedocs.io/en/latest/api.html#application-info) instance loaded in `on_ready`event |
| avatar\_url  |                                        str                                        | Avatar URL of bot loaded in `on_ready`event                                                                        |

### Methods

Methods of [`discord.ext.commands.Bot`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#bots)`+`

* `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       |
