56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
"""Main file for bot."""
|
|
|
|
import pathlib
|
|
|
|
import nextcord
|
|
from nextcord.ext import commands
|
|
|
|
from dakiny_bot.classes.nominate_highcouncil_views import NominateHighCouncilView
|
|
from dakiny_bot.classes.nominate_views import NominateView
|
|
from dakiny_bot.classes.voting_highcouncil_views import VoteHighcouncilView
|
|
from dakiny_bot.classes.voting_views import VoteView
|
|
from dakiny_bot.logger import dakiny_logger
|
|
|
|
from .dakiny_settings import settings
|
|
|
|
birthday_list: list[int] = []
|
|
|
|
|
|
def run() -> None:
|
|
"""Builds and runs bot."""
|
|
# 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 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("dakiny_bot/cogs").iterdir():
|
|
bot.load_extension(f"dakiny_bot.cogs.{folder.name}")
|
|
|
|
@bot.listen()
|
|
async def on_ready() -> None:
|
|
"""When Discord is connected."""
|
|
if bot.user is None:
|
|
dakiny_logger.error("Discord connection failed.")
|
|
return
|
|
|
|
if (guild := bot.get_guild(settings.params.guild_id)) is None:
|
|
dakiny_logger.error("Could not find Dakiny guild object.")
|
|
return
|
|
|
|
bot.add_view(NominateView(guild))
|
|
bot.add_view(NominateHighCouncilView(guild))
|
|
bot.add_view(VoteView(guild))
|
|
bot.add_view(VoteHighcouncilView(guild))
|
|
dakiny_logger.info("%s has connected to Discord!", bot.user.name)
|
|
|
|
# Run Discord bot
|
|
bot.run(settings.params.discord_token)
|