Files
Open-Assistant/discord-bot/CONTRIBUTING.md
T
2022-12-30 04:35:45 -08:00

2.9 KiB

Contributing

Setup

To run the bot

cp .env.example .env

python -V  # 3.10

pip install -r requirements.txt
python -m bot

Before you push, make sure the pre-commit hooks are installed and run successfully.

pip install pre-commit
pre-commit install
pre-commit run --all-files

To test the bot on your own discord server you need to register a discord application at the Discord Developer Portal and get at bot token.

  1. Follow a tutorial on how to get a bot token, for example this one: Creating a discord bot & getting a token
  2. The bot script expects the bot token to be in the .env file under the TOKEN variable.

Resources

Structure

.env                        # Environment variables
.env.example                # Example environment variables
CONTRIBUTING.md             # This file
dev-requirements.txt        # Development requirements
flake8-requirements.txt     # Flake8 extensions (for linting)
noxfile.py                  # Nox session definitions (for formatting, typechecking, linting)
pyproject.toml              # Project configuration
README.md                   # Project readme
requirements.txt            # Requirements
templates/                  # Message templates

bot/
├─  __init__.py
├─  __main__.py         # Entrypoint
├─  bot.py              # Main bot class
├─  config.py           # Configuration and secrets
├─  utils.py            # Utility Functions

├─  db/                 # Database related code
   ├─  database.db     # SQLite database
   └─  schema.sql      # Database schema

└── extensions/         # Application logic, see https://hikari-lightbulb.readthedocs.io/en/latest/guides/extensions.html
    └─   hot_reload.py  # Utility for hot reload extension

Adding a new command/listener

  1. Create a new file in the extensions folder
  2. Copy the template below
# -*- coding: utf-8 -*-
"""My plugin."""
import lightbulb

plugin = lightbulb.Plugin("MyPlugin")

# Add your commands here

def load(bot: lightbulb.BotApp):
    """Add the plugin to the bot."""
    bot.add_plugin(plugin)


def unload(bot: lightbulb.BotApp):
    """Remove the plugin to the bot."""
    bot.remove_plugin(plugin)

For example commands and listeners, see EXAMPLES.md

Docs

Discord

Main framework

Command handler

Component handler (buttons, modals, etc... )