Skip to content

Development Guide

Jedddy edited this page Jan 14, 2023 · 24 revisions

Setting Up

TOKEN

Create a .env file outside the bot folder

│   .gitignore
│   config.yml
│   LICENSE.md
│   poetry.lock
│   pyproject.toml
│   README.md
│   .env  # here
└───bot
    │   config.py
    │   main.py
    ├───cogs
    │       announcements.py
    └───utils
            __init__.py

Then write token="ur discord token here, change this ofc"

ABOUT COGS

Inside cogs/ folder, we will put our Cogs in there.

ABOUT UTILS FOLDER

ABOUT MAIN

The only things we should put inside main.py are the things needed to setup the bot.

CONFIGURATIONS

We have a configurations file named config.yml (DO NOT TOUCH THIS, this will be our production configurations). Since all developers have their own instance of the bot, you have to create your own config file at the root folder of our project. with the explicit name of user-config.yml and put copy the configs inside config.yml then change the configurations to suit your bot instance.

Example, inside your user-config.yml file.

bot:
  prefix: "!"
  token: !ENV "token"
  mod_roles: [] # Put all the mod roles (Role IDs of Moderator Roles) of your `server` inside this. We'll use it for testing administrator commands [925396246208860170, ...]

# more configurations about the bot

Styling

  • pls follow PEP8 standard styling.
  • always annotate your function parameters, and import the Class directly if ever ex:
from discord import Member, TextChannel, Interaction, ...
from discord.app_commands import command


@command()
async def test(self, interaction: Interaction, ...):
    ...

Documentations

UTILITY FUNCTIONS

decorators

We will put our decorator utility functions in here.

Contents:

  • is_staff

is_staff

A decorator for checking if the command invoker is a staff.

def is_staff():
    """
    Example:
        @is_staff()
        @command(description='Bans a member')
        @describe(member='the member to ban')
        async def ban(interaction: discord.Interaction, member: discord.Member):
            await interaction.response.send_message(f'Banned {member}')
    """
    def predicate(interaction: Interaction) -> bool:
        staff = False

        for id_ in Moderation.staff_roles:
            role = interaction.guild.get_role(id_) 

            if role in interaction.user.roles:
                staff = True
                break # Break the loop and continue the command if the invoker is a staff

        return staff
    return app_commands.check(predicate)
Clone this wiki locally