Added slash-commands to reload all cogs aswell as print general information

This commit is contained in:
2024-10-12 23:44:42 +02:00
parent 57282d9c56
commit 709f5df4db
8 changed files with 154 additions and 1 deletions
+19
View File
@@ -14,6 +14,9 @@ import discord
from discord.ext import commands
from pathlib import Path
import re
import sys
import traceback
from utils.portal import Portal
source_path = Path(__file__).resolve()
base_path = source_path.parents[1]
@@ -26,6 +29,12 @@ class MyBot(commands.Bot):
def __init__(self):
super().__init__(command_prefix=None, help_command=None, intents=intents)
async def setup_hook(self):
# Register cogs to handle commands
for cog_name in ["about", "reload"]:
await self.load_extension(f"cogs.{cog_name}")
await self.tree.sync()
bot = MyBot()
bot_config = Advanced_ConfigParser(Path.joinpath(base_path, "config", "bot.ini"))
if re.match(r'[A-Za-z\d]{24}\.[\w-]{6}\.[\w-]{27}', bot_config["DISCORD"]["TOKEN"]):
@@ -41,6 +50,16 @@ else:
async def on_ready():
app_logger.info(f"Successfully logged in (after {get_elapsed_time_smal(datetime.now().timestamp() - startup)}) as {bot.user}")
@bot.tree.error
async def on_app_command_error(ctx, error):
# Traceback für mehr Informationen zum Fehler
print('Ignoring exception in command {}:'.format(ctx.command), file=sys.stderr)
traceback.print_exception(type(error), error, error.__traceback__)
# Execute some housekeeping actions
portal = Portal.instance()
portal.bot_config = bot_config
try:
bot.run(bot_config["DISCORD"]["TOKEN"], log_handler = None)
except discord.errors.LoginFailure: