Files
cogs
bot.py
config.json
config.py
database.py
requirements.txt
utils.py
Code
10 666
bot.py
import logging
import os
import discord
from discord.ext import commands
from config import PREFIX, TOKEN
from database import Database
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s")
logger = logging.getLogger("kodari")
class KodariBot(commands.Bot):
def __init__(self):
intents = discord.Intents.all()
super().__init__(command_prefix=PREFIX, intents=intents, help_command=None)
self.db = Database()
self.synced = False
async def setup_hook(self):
await self.db.initialize()
for extension in ("cogs.core", "cogs.security", "cogs.server"):
try:
await self.load_extension(extension)
except Exception:
logger.exception("Unable to load %s", extension)
async def on_ready(self):
if not self.synced:
await self.tree.sync()
self.synced = True
await self.change_presence(activity=discord.Game(name=f"{PREFIX}modules | Security"))
logger.info("Logged in as %s (%s)", self.user, self.user.id)
async def on_command_error(self, ctx: commands.Context, error: commands.CommandError):
if isinstance(error, commands.CommandNotFound):
return
if isinstance(error, commands.MissingPermissions):
await ctx.send("You do not have permission to use that command.", delete_after=8)
return
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send(f"Missing argument: `{error.param.name}`", delete_after=8)
return
logger.exception("Prefix command failed", exc_info=error)
await ctx.send("That command could not be completed.", delete_after=8)
if __name__ == "__main__":
if not TOKEN:
raise RuntimeError("DISCORD_TOKEN is missing. Add it to .env before starting the bot.")
KodariBot().run(TOKEN, log_handler=None)