A discord bot for our community
- You need to setup the following environment variables in your
.envfile:BOT_TOKEN={our_bot_token} API_URL={our_url_to_api} GOOGLESHEET_ID={our_google_sheet_id} GOOGLESHEET_PRIVATE_KEY_ID={our_googlesheet_private_key_id} GOOGLESHEET_PRIVATE_KEY={our_googlesheet_private_key} GOOGLESHEET_CLIENT_ID={our_googlesheet_client_id}
- Go download uv before run the bot with this command:
uv run bot.py
To create a Discord bot, follow these steps:
- Create an application at the Discord Developer Portal.
- Navigate to the
Botsection on the left panel and get the bot token, then set up your environment variables. - Configure the
Default Install Settingsin theInstallationsection:- SCOPES
applications.commandsbot
- PERMISSIONS
Embed LinksMention EveryoneSend MessagesUse Slash CommandsView Channels
- SCOPES
- Copy the
Install Linkfrom above and use it to invite the bot to your server.
To create a command, first make a file under /cogs, then append this file name after COGS in config/settings.py:
COGS= [
"cogs.dict_query",
...,
"cogs.{your_file_name}"
]Then you can work on implementing the function of that command. Here is the quick template to build your command:
import discord
from discord import app_commands
from discord.ext import commands
from core.bot_core import KumaBot
class YOUR_COMMAND_CLASS(commands.Cog):
def __init__(self, bot: KumaBot):
self.bot = bot
@app_commands.command(name="command", description="xxxxx")
async def your_command_function(self, interaction: discord.Interaction):
pass
async def setup(bot: KumaBot):
await bot.add_cog(YOUR_COMMAND_CLASS(bot))Since the package of ruff and mypy are already installed in dev group, one can directly execute the following command to format and check the project:
ruff format . --check # Check format
ruff check . # Check linter
mypy . # Check typeFor more detailed setting with IDE (e.g. VScode), please refer to our manual.