-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
64 lines (51 loc) · 2.01 KB
/
run.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
from typing import Optional
import discord
from dbl import DBLClient
from dotenv import load_dotenv
from discord.ext.commands import AutoShardedBot, errors
from os import getenv
from models import PostgreSQL, AbstractDataBase
load_dotenv() # reloads .env to memory
class WeverseBot(AutoShardedBot):
def __init__(self, command_prefix, **options):
super().__init__(command_prefix, **options.get("options"))
self.conn: AbstractDataBase = PostgreSQL(**options.get("db_kwargs")) # db connection
top_gg_key = getenv("TOP_GG_KEY")
self.top_gg_client: Optional[DBLClient] = None if not top_gg_key else DBLClient(self, top_gg_key, autopost=True)
async def on_command_error(self, context, exception):
if isinstance(exception, errors.CommandNotFound):
...
elif isinstance(exception, errors.CommandInvokeError):
try:
if exception.original.status == 403:
return
except AttributeError:
return
return await context.send(f"{exception}")
elif isinstance(exception, errors.BadArgument):
return await context.send(f"{exception}")
else:
...
if __name__ == '__main__':
intents = discord.Intents.default()
# intents.members = True # turn on privileged members intent
# intents.presences = True # turn on presences intent
kwargs = {
"options": {
"case_insensitive": True,
"owner_id": int(getenv("BOT_OWNER_ID")),
"intents": intents
},
"db_kwargs": {
"host": getenv("POSTGRES_HOST"),
"database": getenv("POSTGRES_DATABASE"),
"user": getenv("POSTGRES_USER"),
"password": getenv("POSTGRES_PASSWORD"),
"port": getenv("POSTGRES_PORT")
}
}
bot = WeverseBot(getenv("BOT_PREFIX"), **kwargs)
cogs = ["BotInfo", "Weverse"]
for cog in cogs:
bot.load_extension(f"cogs.{cog}")
bot.run(getenv("BOT_TOKEN"))