-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (38 loc) · 1.47 KB
/
main.py
File metadata and controls
55 lines (38 loc) · 1.47 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
43
44
45
46
47
48
49
50
51
import os
import logging
import platform
import discord
from discord.ext import commands, tasks
from sqlalchemy.orm import sessionmaker
from classes import World
from executeQueue import ExecuteQueue
# import required files
import database
import execute_fixtures
class Client(commands.Bot):
def __init__(self):
super().__init__(command_prefix='.', intents=discord.Intents().default())
self.world_count = 0
async def setup_hook(self):
for fileName in os.listdir('commands'):
if fileName.endswith('.py'):
extension = f'commands.{fileName[:-3]}'
await self.load_extension(extension)
await self.tree.sync()
async def on_ready(self):
print(f"Logged in as {self.user.name}")
print(f"Bot ID {str(self.user.id)}")
print(f"Discord Version {discord.__version__}")
print(f"Python Version {str(platform.python_version())}")
logging.warning("Now logging..")
# get the initial world count on startup
Session = sessionmaker(bind=database.engine)
session = Session()
self.world_count = session.query(World).count()
self.update_bot_status.start()
ExecuteQueue(client=self).start()
@tasks.loop(seconds=60)
async def update_bot_status(self):
await self.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=f"{self.world_count} worlds"))
client = Client()
client.run(os.getenv("token"))