selena/main.py

53 lines
1.4 KiB
Python
Raw Normal View History

import logging
2024-06-20 21:43:01 -04:00
import discord
2024-06-20 21:43:01 -04:00
import config
# Set up logging
logging.basicConfig(level=logging.DEBUG)
2024-06-20 21:43:01 -04:00
class Selena(discord.Client):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.tree = discord.app_commands.CommandTree(self)
async def setup_hook(self):
2024-06-21 13:22:13 -04:00
guild = discord.Object(id=config.DISCORD_GUILD_ID)
await self.load_extensions()
2024-06-21 13:22:13 -04:00
self.tree.copy_global_to(guild=guild)
await self.tree.sync(guild=guild)
2024-06-20 21:43:01 -04:00
async def load_extension(self, name):
module = __import__(name, fromlist=["setup"])
await module.setup(self)
async def load_extensions(self):
# Mandatory modules that cannot be disabled
mandatory_modules = [
"modules.admin.logger_module",
"modules.admin.policy_module",
]
# Load mandatory modules
for extension in mandatory_modules:
await self.load_extension(extension)
# Load enabled modules from configuration
for extension in config.ENABLED_MODULES:
await self.load_extension(extension)
2024-06-20 21:43:01 -04:00
async def on_ready(self):
print(f"Logged in as {self.user} (ID: {self.user.id})")
print("------")
2024-06-20 21:43:01 -04:00
if __name__ == "__main__":
# Enable message content intent
2024-06-20 21:43:01 -04:00
intents = discord.Intents.default()
intents.message_content = True
2024-06-20 21:43:01 -04:00
client = Selena(intents=intents)
client.run(config.DISCORD_TOKEN)