Преглед изворни кода

Fixing problems with the log print

BaumSplitter41 пре 4 месеци
родитељ
комит
b4418a0346
1 измењених фајлова са 8 додато и 5 уклоњено
  1. 8 5
      VPD_BOT/main.py

+ 8 - 5
VPD_BOT/main.py

@@ -130,7 +130,7 @@ bot = commands.Bot(
 )
 
 #Loading Cogs
-def load_extensions():
+async def load_extensions():
     cogs_dir = "./cogs"
     if bot.guilds:
         channel = discord.utils.get(bot.guilds[0].channels, id=int(channel_log))
@@ -143,10 +143,12 @@ def load_extensions():
             try:
                 bot.load_extension(f"cogs.{cog_list}")
                 print(f"Loaded cog: {cog_list}")
-                channel.send(f"Loaded Cogs:{cog_list}")
+                if bot.guilds and channel:
+                    await channel.send(f"Loaded Cogs:{cog_list}")
             except Exception as e:
                 print(f"Failed to load cog {cog_list}: {e}")
-                channel.send(f"Failed to load cog {cog_list}: {e}")
+                if bot.guilds and channel:
+                    await channel.send(f"Failed to load cog {cog_list}: {e}")
 
 class Admin(commands.Cog):
     def __init__(self, bot):
@@ -171,10 +173,12 @@ async def on_ready():
         if channel:
             await channel.send(f"{bot.user} is online")
     bot.add_view(PersistentRoleView()) #loading reactionrole memory
+    await load_extensions()
     print("Registrierte Slash-Commands:")
     for command in bot.pending_application_commands:
         print(f" - {command.name}")
-        await channel.send(f"- {command.name}")
+        if bot.guilds and channel:
+            await channel.send(f"- {command.name}")
         
 #---------------------------------------------------------------------------------------#
 #DONT Touch anything above this line, unless you know what you are doing!#
@@ -530,6 +534,5 @@ async def setup_rr(
 
 #---------------------------------#
 #Run function
-load_extensions()
 bot.run(token)
 #---------------------------------#