50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
"""
|
|
The discord bot for the application.
|
|
"""
|
|
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
from discord import Intents, Game
|
|
from discord.ext import commands
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
class DiscordBot(commands.Bot):
|
|
|
|
def __init__(self, BASE_DIR: Path, developing: bool, api_token: str):
|
|
activity = Game("Indev") if developing else None
|
|
super().__init__(command_prefix="-", intents=Intents.all(), activity=activity)
|
|
self.BASE_DIR = BASE_DIR
|
|
self.developing = developing
|
|
self.api_token = api_token
|
|
|
|
log.info("developing=%s", developing)
|
|
|
|
async def sync_app_commands(self):
|
|
"""
|
|
Sync application commands between discord and the bot.
|
|
"""
|
|
|
|
await self.wait_until_ready()
|
|
await self.tree.sync()
|
|
log.info("Application commands successfully synced")
|
|
|
|
async def on_ready(self):
|
|
"""
|
|
Execute init operations that require the bot to be ready.
|
|
Ideally should not be manually called, this is handled by discord.py
|
|
"""
|
|
|
|
await self.sync_app_commands()
|
|
|
|
async def load_extensions(self):
|
|
"""
|
|
Load any extensions found in the extensions dictionary.
|
|
"""
|
|
|
|
for path in (self.BASE_DIR / "src/extensions").iterdir():
|
|
if path.suffix == ".py":
|
|
await self.load_extension(f"extensions.{path.stem}")
|