-
Notifications
You must be signed in to change notification settings - Fork 7
Development Guide
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 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"
database:
database:
name: !ENV "db_name"
host: !ENV "db_host"
user: !ENV "db_user"
password: !ENV "db_pass"
guild:
staff_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, ...]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
Inside your .env file write the following:
token="your bot token"
db_host="your db host"
db_user="your username on your database"
db_pass="your local db password"
db_name="your local database name"
Inside cogs/ folder, we will put our Cogs in there.
The only things we should put inside main.py are the things needed to setup the bot.
- 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, ...):
...We will put our decorator utility functions in here. You can refer to this if you want to make your own decorator.
Contents:
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)