-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·72 lines (60 loc) · 2 KB
/
main.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python3
"""
Title: Main
Type: Main Program
Purpose: Start the whole thing!
Author: AG | MuirlandOracle
Last Updated: 24/02/21
"""
import discord, asyncio, os, argparse, sys, datetime, signal
from discord.ext import commands
from discord.ext.commands import CommandNotFound, MissingRequiredArgument
from dotenv import load_dotenv
from libs.loadconf import config, secrets
from libs.colours import Colours as colours
from libs.logging import Log as log
#Signal Handling
def exiting():
log.end()
colours.success("Exiting...")
sys.exit(0)
def sigHandle(sig, frame):
exiting()
signal.signal(signal.SIGINT, sigHandle)
#Bot Setup
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix=config["prefix"], intents=intents)
bot.remove_command("help")
#Record start time in environment variable
os.environ["GAMEATHON-START"] = str(datetime.date.today())
#Loading Cogs
def loadCogs():
for cog in config["cogs"]:
try:
bot.load_extension(cog)
colours.success(f"{cog} loaded successfully")
except Exception as e:
colours.warn(f"{cog} failed to load: {e}")
#Change the status of the bot once connected to the server
@bot.event
async def on_ready():
if config["status"] != "":
await bot.change_presence(activity=discord.Game(config["status"]))
colours.success("Connected")
#Get rid of the output from people typing commands that don't exist (or forgetting to add a command argument)
@bot.event
async def on_command_error(ctx, error):
error_to_skip = [CommandNotFound, MissingRequiredArgument]
for error_type in error_to_skip:
if isinstance(error, error_type):
return
raise error
#Release the bot!
if __name__ == "__main__":
log.start() #Start Logging
loadCogs() #Load the cogs
try:
bot.run(secrets["TOKEN"]) #Start the bot -- if the token doesn't exist, maybe try adding this
except RuntimeError:
exiting()