-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.py
65 lines (47 loc) · 2.29 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from config import *
from utils import *
from nextcord import Embed, ApplicationInvokeError, Forbidden, Interaction, DiscordServerError, Color
from nextcord.ext.commands import Bot as NextcordBot
from datetime import datetime
import logging
class Bot(NextcordBot):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.initialised = False
self.logger = Logger("bot", "logs/bot.log", print_level=logging.DEBUG)
self.loaded_cogs: dict[str, int] = {} # {cog path: last modified time}
# Prevents errors from being printed twice
async def on_application_command_error(self, interaction: Interaction, error: ApplicationInvokeError):
pass
async def handle_interaction_error(self, interaction: Interaction, exception: Exception):
"""|coro|
Handles an interaction error
Parameters
----------
interaction: :class:`Interaction`
The interaction that raised the error
exception: :class:`Exception`
The exception that was raised
"""
if isinstance(exception, Forbidden):
embed = Embed(title="**Erreur de permissions**", description="I don't have the necessary permissions to perform this action", color=Color.red())
await interaction.send(embed=embed, ephemeral=True)
else:
self.logger.error("An unexpected error occured")
self.logger.error(interaction.user, f"({interaction.user.id})")
self.logger.exception(exception)
embed = Embed(title="An unexpected error occured", color=Color.red(), timestamp=datetime.now())
await interaction.send(embed=embed, ephemeral=True)
async def handle_task_error(self, exception: Exception, task: str):
"""|coro|
Handles a task error
Parameters
----------
exception: :class:`Exception`
The exception that was raised
task: :class:`str`
The name of the task that raised the error
"""
if not isinstance(exception, DiscordServerError):
self.logger.error(f"An unexpected error occured in task `{task}`")
self.logger.exception(exception)