-
Notifications
You must be signed in to change notification settings - Fork 3
/
run.py
49 lines (36 loc) · 1.33 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
import os
import hikari
import lightbulb
import miru
import config as c
# Unix optimizations
# https://github.com/hikari-py/hikari#uvloop
if os.name != "nt":
import uvloop
uvloop.install()
bot = lightbulb.BotApp(
token=c.config["token"],
default_enabled_guilds=c.config["guilds"],
help_slash_command=False,
)
# Listener for global command exceptions
@bot.listen(lightbulb.CommandErrorEvent)
async def on_error(event):
error = c.ERROR
match event.exception.__cause__ or event.exception:
case lightbulb.BotMissingRequiredPermission():
error = f"***Missing required permissions: `{event.exception.missing_perms}`***"
case lightbulb.MissingRequiredPermission():
error = f"***You are missing required permissions: `{event.exception.missing_perms}`***"
case hikari.ForbiddenError():
raise event.exception
case _:
await bot.application.owner.send(c.error(event))
try:
await event.context.respond(error, flags=hikari.MessageFlag.EPHEMERAL)
except:
await event.context.interaction.edit_initial_response(error, components=None)
raise event.exception
miru.install(bot)
bot.load_extensions_from("tools", "commands")
bot.run(activity=hikari.Activity(name=c.config["activity"], type=c.ACTIVITY) if c.config["activity"] else None)