43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
"""Main file for Agon bot."""
|
|
|
|
import pathlib
|
|
import sys
|
|
|
|
import nextcord
|
|
from nextcord.ext import commands
|
|
|
|
from . import config
|
|
from .logger import agon_logger
|
|
|
|
|
|
def run() -> None:
|
|
"""Main function for bot."""
|
|
min_python_version = (3, 12)
|
|
if sys.version_info < min_python_version:
|
|
agon_logger.error("ERROR: Python version must be >= 3.12")
|
|
sys.exit()
|
|
|
|
# Allows privileged intents for monitoring members joining, roles editing, and role assignments
|
|
# These need to be enabled in the developer portal as well
|
|
intents = nextcord.Intents.default()
|
|
|
|
bot = commands.Bot(
|
|
commands.when_mentioned_or(config.BOT_PREFIX),
|
|
intents=intents,
|
|
)
|
|
|
|
# Get the modules of all cogs whose directory structure is ./cogs/<module_name>
|
|
for folder in pathlib.Path("./agon/cogs").iterdir():
|
|
bot.load_extension(f"agon.cogs.{folder.name}")
|
|
|
|
@bot.listen()
|
|
async def on_ready() -> None:
|
|
"""When Discord is connected."""
|
|
if bot.user is None:
|
|
agon_logger.error("Discord connection failed.")
|
|
return
|
|
agon_logger.info("%s has connected to Discord!", bot.user.name)
|
|
|
|
# Run Discord bot
|
|
bot.run(config.DISCORD_TOKEN)
|