33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
# bot_discord.py
|
|
import discord
|
|
from discord.ext import commands
|
|
import importlib
|
|
import cmd_discord
|
|
|
|
class DiscordBot(commands.Bot):
|
|
def __init__(self, config, log_func):
|
|
super().__init__(command_prefix="!", intents=discord.Intents.all())
|
|
self.config = config
|
|
self.log = log_func # Use the logging function from bots.py
|
|
self.load_commands()
|
|
|
|
def load_commands(self):
|
|
"""
|
|
Load all commands dynamically from cmd_discord.py.
|
|
"""
|
|
try:
|
|
importlib.reload(cmd_discord)
|
|
cmd_discord.setup(self)
|
|
self.log("Discord commands loaded successfully.", "INFO")
|
|
except Exception as e:
|
|
self.log(f"Error loading Discord commands: {e}", "ERROR")
|
|
|
|
async def on_ready(self):
|
|
self.log(f"Discord bot is online as {self.user}", "INFO")
|
|
|
|
async def run(self, token):
|
|
try:
|
|
await super().start(token)
|
|
except Exception as e:
|
|
self.log(f"Discord bot error: {e}", "CRITICAL")
|