60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
"""Main file for bot."""
|
|
|
|
import logging
|
|
import os
|
|
|
|
import nextcord
|
|
from nextcord.ext import commands
|
|
|
|
from classes.nominate_highcouncil_views import NominateHighCouncilView
|
|
from classes.nominate_views import NominateView
|
|
from classes.voting_highcouncil_views import VoteHighcouncilView
|
|
from classes.voting_views import VoteView
|
|
from DakinySettings import settings
|
|
from database_setup import create_database
|
|
|
|
birthday_list: list[int] = []
|
|
|
|
logger = logging.getLogger("nextcord")
|
|
logger.setLevel(logging.DEBUG)
|
|
handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8", mode="w")
|
|
handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
|
|
logger.addHandler(handler)
|
|
|
|
|
|
def main() -> 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 os.listdir("cogs"):
|
|
bot.load_extension(f"cogs.{folder}")
|
|
|
|
@bot.listen()
|
|
async def on_ready() -> None:
|
|
"""When Discord is connected."""
|
|
assert bot.user is not None # noqa: S101 documentation does this
|
|
create_database # noqa: B018
|
|
bot.add_view(NominateView(bot.get_guild(settings.params.guild_id)))
|
|
bot.add_view(NominateHighCouncilView(bot.get_guild(settings.params.guild_id)))
|
|
bot.add_view(VoteView(bot.get_guild(settings.params.guild_id)))
|
|
bot.add_view(VoteHighcouncilView(bot.get_guild(settings.params.guild_id)))
|
|
print(f"{bot.user.name} has connected to Discord!") # noqa: T201 TODO make logging to print my stuff to console
|
|
|
|
# Run Discord bot
|
|
bot.run(settings.params.discord_token)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|