-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbot.py
executable file
·48 lines (37 loc) · 1.42 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import json
import logging
import os
import sys
import discord
from discord.ext import commands
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
if not os.path.isfile("config.json"):
sys.exit("'Config file not found! Please add it and try again.")
else:
with open("config.json") as file:
config = json.load(file)
intents = discord.Intents.default()
intents.members = True
intents.messages = True
intents.message_content = True
class Bot(commands.Bot):
def __init__(self):
super().__init__(command_prefix=config['prefix'], intents=intents)
async def startup(self):
await bot.wait_until_ready()
await bot.tree.sync()
await bot.change_presence(activity=discord.Game(name='Wengerball'))
logging.info('Successfully synced applications commands')
logging.info(f'Connected as {bot.user}')
async def setup_hook(self):
for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
try:
await bot.load_extension(f"cogs.{filename[:-3]}")
logging.info(f"Loaded {filename}")
except Exception as e:
logging.error(f"Failed to load {filename}")
logging.error(f"[ERROR] {e}")
self.loop.create_task(self.startup())
bot = Bot()
bot.run(config["token"])