import nextcord from nextcord.ext import application_checks, commands from nextcord import SlashOption from dotenv import load_dotenv from random import randint import aiohttp import aiosqlite as sqlite3 import traceback from urllib.parse import urlparse import os import logging import sys load_dotenv() bot = commands.Bot() @bot.event async def on_ready(): global db global cur db = await sqlite3.connect("/data/mmolb.sqlite") cur = await db.cursor() res = await cur.execute("SELECT name FROM sqlite_master WHERE name='liveupdate'") if await res.fetchone() is None: await cur.execute("CREATE TABLE liveupdate(serverid INTEGER, userid INTEGER, channelid INTEGER NOT NULL, messageid INTEGER, gameid TEXT, offset INTEGER)") await db.commit() res = await cur.execute("SELECT name FROM sqlite_master WHERE name='spotlightsubscriptions'") if await res.fetchone() is None: await cur.execute("CREATE TABLE spotlightsubscriptions(serverid INTEGER, channelid INTEGER NOT NULL)") await db.commit() res = await cur.execute("SELECT name FROM sqlite_master WHERE name='teamsubscriptions'") if await res.fetchone() is None: await cur.execute("CREATE TABLE teamsubscriptions(serverid INTEGER, channelid INTEGER NOT NULL, teamid TEXT)") await db.commit() bot.db = db bot.cur = cur bot.load_extension('cogs.team') #Must load first as it contains autofill code bot.load_extension('cogs.liveupdate') bot.load_extension('cogs.error') bot.add_all_application_commands() await bot.sync_all_application_commands() @bot.slash_command( name="managecog", description="manage cogs", guild_ids=[int(os.getenv("OWNER_GUILD"))], ) @application_checks.is_owner() async def managecog(interaction: nextcord.Interaction, action: str = SlashOption(choices=["load", "unload", "reload","sync"]), cog: str = SlashOption(required=False) ): errors = "" try: if action == "load": bot.load_extension(cog) elif action == "unload": bot.unload_extension(cog) elif action == "reload": bot.reload_extension(cog) elif action == "sync": bot.add_all_application_commands() await bot.sync_all_application_commands() await interaction.response.send_message(f"Done!" + (f"\n{errors}" if errors != "" else ""), ephemeral=True) except Exception as e: await interaction.response.send_message(e, ephemeral=True) bot.run(os.getenv("TOKEN"))