Template
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
"""Main file for bot."""
|
|
|
|
import os
|
|
|
|
import nextcord
|
|
from nextcord.ext import commands
|
|
|
|
from .settings import settings
|
|
|
|
|
|
def run() -> 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
|
|
|
|
# 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(f"${REPO_NAME_SNAKE}/cogs"):
|
|
bot.load_extension(f"${REPO_NAME_SNAKE}.cogs.{folder}")
|
|
|
|
@bot.listen()
|
|
async def on_ready() -> None:
|
|
"""When Discord is connected."""
|
|
if bot.user is None:
|
|
print("Discord connection failed.")
|
|
return
|
|
print(f"{bot.user.name} has connected to Discord!")
|
|
|
|
# Run Discord bot
|
|
bot.run(settings.params.discord_token)
|