-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.py
33 lines (28 loc) · 1.83 KB
/
bot.py
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
import nextcord, os
from nextcord.ext import commands
from constants import TOKEN
from utils import colour_message
class Bot(commands.Bot):
def __init__(self) -> None:
super().__init__(command_prefix="nom!", intents=nextcord.Intents.all()) # Creates a new bot instance
self.unloaded_cogs = []
def initialize(self) -> None:
os.system("cls") # Clears the terminal for easy reading
print(colour_message(message='Snipe Bot Online', color="yellow"))
print(colour_message(message="Bot has started", color="green"))
self.load_extensions()
self.run(TOKEN) # Runs the bot, using the token
def load_extensions(self) -> None: # Loads the cog extensions
for folder in os.listdir("./cogs"): # Finds all the folders in cogs folder
for cog in os.listdir(f"./cogs/{folder}"): # For each folder finds all files
if cog.endswith(".py"): # Checks if the file is a python file
try: # If a file errors it will trip this try/except
self.load_extension(name=f"cogs.{folder}.{cog[:-3]}") # Loads each cog
print(colour_message(message=f"Loaded {cog[:-3]} cog", color="blue"))
except Exception as e: # Catches each error and prints it to console
print(e)
print(colour_message(message=f"Failed to load {cog[:-3]} cog", color="yellow"))
self.unloaded_cogs.append(cog.capitalize()[-3])
async def on_ready(self) -> None: # Runs when the bot is ready to be used
print(colour_message(message=f"Logged in as {self.user}!", color="green"))
await self.change_presence(status=nextcord.Status.online, activity=nextcord.Activity(type=nextcord.ActivityType.playing, name="Sniping Deleted Messages")) # Sets the bots status