-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
42 lines (30 loc) · 1.44 KB
/
Copy pathmain.py
File metadata and controls
42 lines (30 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
""" Imports """
# System Imports
import os
import logging
import asyncio
from dotenv import load_dotenv
# Pycord Imports
import discord
load_dotenv() # load the .env file
logging.basicConfig(level=logging.INFO) # setup default logger to track bot events and errors
""" Intents tell Discord what your bot needs to work, will require approval after you reach 100 servers """
intents = discord.Intents.none() # less memory usage if we use only the intents we need
intents.guilds = True # to know what guilds the bot is in
intents.members = True # to know what members guilds have
""" Main Bot """
client = discord.Bot(intents=intents) # initialize the bot
async def load_cogs(): # load cogs
loaded_cogs = 0
failed_cogs = 0
for filename in os.listdir("cogs"): # for each file in the "cogs" folder
if filename.endswith(".py"): # check if it's a python file
try:
client.load_extension(f"cogs.{filename[:-3]}") # load cog
loaded_cogs += 1 # add 1 more loaded cog to loaded_cogs
except discord.ExtensionError as error:
logging.error(f"Failed to load '{filename}': {error}") # log error
failed_cogs += 1 # add 1 more failed cog to failed_cogs
logging.info(f"Successfully loaded {loaded_cogs} cog(s), and {failed_cogs} failed.")
asyncio.run(load_cogs())
client.run(os.getenv("DISCORD_TOKEN")) # finally start the bot, any code after this will not run