This repository has been archived on 2025-04-28. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
off-cooldown-bot/off_cooldown_bot/main.py
T
imcompiling 54a011337a
build_develop / build (push) Successful in 21s
Fix debugger module and imports.
2025-03-18 21:45:12 -04:00

57 lines
1.7 KiB
Python

"""Main file for bot."""
from __future__ import annotations
import logging
import pathlib
import nextcord
from logger import ocd_logger
from nextcord.ext import commands
from settings import settings
nextcord_logger = logging.getLogger("nextcord")
nextcord_logger.setLevel(logging.DEBUG)
nextcord_handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8", mode="w")
nextcord_handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
nextcord_logger.addHandler(nextcord_handler)
birthday_list: list[int] = []
def main() -> None:
"""Set config, intents, then connects the bot to discord."""
# 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()
# Required in order to read messages (eg. prefix commands)
intents.message_content = True
# To enable the guilds privileged intent:
# intents.guilds = True # noqa: ERA001
# To enable the members privileged intent:
intents.members = True
bot = commands.Bot(intents=intents)
# Get the modules of all cogs whose directory structure is ./cogs/<module_name>
for folder in pathlib.Path("cogs").iterdir():
bot.load_extension(f"cogs.{folder.name}")
@bot.listen()
async def on_ready() -> None:
"""When Discord is connected."""
if bot.user is None:
ocd_logger.critical("Discord connection failed.")
return
ocd_logger.info("%s has connected to Discord!", bot.user.name)
# Run Discord bot
bot.run(settings.params.discord_token)
if __name__ == "__main__":
main()