Skip to content

An advanced discord bot made with discord.py 2.0.0. Context commands, Views, Modals, Slash commands, Hybrid commands, Group commands, commands, database support, dynamic structure, error-handling, logging, ANSI, translator and more.

License

Notifications You must be signed in to change notification settings

bsavage81/Discord-Bot

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub is maintained CodeQL Deploy

Contributors GitHub last commit GitHub last release Github last prerelease

Discord-Bot

Table of content

About the project

This discord bot was made for an IT School in 2020. It has a lot of features including all the latest features from discord.py. Made by student(s) for students.

Note: Major features

  • ContextMenus (Right-click commands)
  • AppCommands (Slash-commands)
  • HybridCommands (Slash-commands + Commands)
  • Groups
  • Commands
  • Custom-Modals (Forms)
  • Custom-Views (Buttons, Dropdown, ..)
  • Cogs/GroupCogs
  • Custom prefix per guild
  • Dynamic structure (Does not require a reboot to apply changes in files)
  • Database support (SQL)
  • Error handling
  • Logging
  • Multiple configs
  • Powerful, dev & debuging commands
  • Metrics about usage of the bot
  • Language detector & Translation
  • And much more..

Built with

Getting started

Python Prerequisites

Install python packages with:

  • pip
$ pip install -r requirements.txt

Discord developper configuration

  1. Create a application on Discord Developpers

  2. Enable the bot status in Discord Developpers/applications/{YOUR_APP_ID}/bot

  3. Please make sure you have activated each Privileged Gateway Intents in Discord Developpers/applications/{YOUR_APP_ID}/bot #Privileged Gateway Intents for your application.

  4. Copy the token bot from Discord Developpers/applications/{YOUR_APP_ID}/bot #Token

Note In URL replace {YOUR_APP_ID} with your own app/bot ID.

Configure the bot

  1. Paste your dicord bot token in the "token" field inside /config/bot.json.

  2. Configure the prefix in the /config/bot.json.

  3. If you're using a database, you need to configure the /config/database.json file.

Warning If you're NOT using any database, check this section of the documentation.

Database

Acknowledgement

Warning If you have not plan to use a SQL database:

  • in the folder cogs you should remove the following files: birthday.py, croissants.py, invite.py, me.py, metrics.py, starboard.py.
  • in cogs/admin.py remove the change_guild_prefix method.
  • in bot.py replace the command_prefix=__getprefix line 12 with command_prefix="?" (define the bot's prefix).
  • in bot.py delete the Database initialization (line 41-44) and the Prefix per guild initialization (line 46-48).

Note If you have plan to use a database:

  • you should use a SQL Database.
  • reconfigure the "server" section from /config/database.json.
  • you can change the subjective structure of each tables if needed.
    • if so you should reconfigure some keys/values of the /config/database.json.

SQL tables structure

Note These tables are required in the database if you have planned to use the bot as if provided

  • table_birthday
CREATE TABLE IF NOT EXISTS `table_birthday`
(
    `user_id`           BIGINT unsigned NOT NULL,
    `user_birth`        DATE NOT NULL,
UNIQUE(`user_id`)
)
ENGINE = InnoDB,
CHARACTER SET utf8mb4,
COLLATE utf8mb4_unicode_ci;
  • table_croissants
CREATE TABLE IF NOT EXISTS `table_croissants`
(
    `user_id`           BIGINT unsigned NOT NULL,
    `user_count`        SMALLINT unsigned,
UNIQUE(`user_id`)
)
ENGINE = InnoDB,
CHARACTER SET utf8mb4,
COLLATE utf8mb4_unicode_ci;
  • table_fridaycake
CREATE TABLE IF NOT EXISTS `table_fridaycake`
(
    `user_isin`         BOOLEAN NOT NULL,
    `user_id`           BIGINT unsigned NOT NULL,
    `user_name`         varchar(32) NOT NULL,
UNIQUE(`user_id`)
)
ENGINE = InnoDB,
CHARACTER SET utf8mb4,
COLLATE utf8mb4_unicode_ci;
  • table_invite
CREATE TABLE IF NOT EXISTS `table_invite`
(
    `guild_id`           BIGINT unsigned NOT NULL,
    `channel_id`         BIGINT unsigned NOT NULL,
    `custom_message`     varchar(4096),
UNIQUE(`guild_id`)
)
ENGINE = InnoDB,
CHARACTER SET utf8mb4,
COLLATE utf8mb4_unicode_ci;
  • table_me
CREATE TABLE IF NOT EXISTS `table_me`
(
    `guild_id`          BIGINT unsigned NOT NULL,
    `user_id`           BIGINT unsigned NOT NULL,
    `user_me`           varchar(1024),
CONSTRAINT `me_per_guild` UNIQUE (`guild_id`, `user_id`)
)
ENGINE = InnoDB,
CHARACTER SET utf8mb4,
COLLATE utf8mb4_unicode_ci;
  • table_metrics
CREATE TABLE IF NOT EXISTS `table_metrics`
(
    `command_name`      varchar(32) NOT NULL,
    `command_count`     MEDIUMINT unsigned NOT NULL,
    `command_type`      varchar(64) NOT NULL,
UNIQUE(`command_name`)
)
ENGINE = InnoDB,
CHARACTER SET utf8mb4,
COLLATE utf8mb4_unicode_ci;
  • table_prefix
CREATE TABLE IF NOT EXISTS `table_prefix`
(
    `guild_id`           BIGINT unsigned NOT NULL,
    `guild_prefix`       varchar(256),
UNIQUE(`guild_id`)
)
ENGINE = InnoDB,
CHARACTER SET utf8mb4,
COLLATE utf8mb4_unicode_ci;
  • table_starboard
CREATE TABLE IF NOT EXISTS `table_starboard`
(
    `reference_message`   VARCHAR(100) NOT NULL,
    `display_message`     VARCHAR(100) NOT NULL,
    `star_count`          SMALLINT unsigned NOT NULL,
UNIQUE(`reference_message`)
)
ENGINE = InnoDB,
CHARACTER SET utf8mb4,
COLLATE utf8mb4_unicode_ci;

Workflows

Update and restart discord bot

Github setup:

  • On Github.com go on your project repository
  • Then click on Settings > Actions > Runners > New self-hosted runner.
  • Then select the right runner-image related to your machine and the right architecture.
  • Then follow the Download and the Configure instructions.

Server setup:

  • If you want to start the self-runner on boot, you can follow this guide. :warning: The self-hosted runner should have the following permissions, install apps and start/restart services. (install the service as --user usernameWithPermissions)

Discord bot service: This step is made for linux only.

  • Create a service file in /etc/systemd/system/your-service-name.service with the following content:
[Unit]
Description=Discord bot startup service
After=multi-user.target

[Service]
Type=simple
Restart=no
User={usernameWithPermissions}
WorkingDirectory=/home/{username}/actions-runner/_work/Discord-Bot/Discord-Bot
ExecStart=python3 /home/{username}/actions-runner/_work/Discord-Bot/Discord-Bot/bot.py

[Install]
WantedBy=multi-user.target

Note Replace {username} & {usernameWithPermissions} with your username and Discord-Bot/Discord-Bot with your project name.

  • Then enable the service with systemctl enable your-service-name.service
Contributors :

About

An advanced discord bot made with discord.py 2.0.0. Context commands, Views, Modals, Slash commands, Hybrid commands, Group commands, commands, database support, dynamic structure, error-handling, logging, ANSI, translator and more.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%