-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
75 lines (63 loc) · 2.26 KB
/
Copy pathmain.py
File metadata and controls
75 lines (63 loc) · 2.26 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import discord
from discord.ext import commands
from constant import TOKEN
from utils.ops_log import emit_command_error
from utils.ops_log import emit_exception_event
from utils.ops_log import emit_startup_event
extensions = (
'auto_thread',
'thread_manage',
)
class MyBot(commands.Bot):
def __init__(self):
super().__init__(
command_prefix=commands.when_mentioned_or('$'),
intents=discord.Intents.all(),
)
self._startup_event_sent = False
async def setup_hook(self):
try:
for extension in extensions:
await self.load_extension(f'extensions.{extension}')
await self.tree.sync()
except Exception as error:
await emit_exception_event(
'config_error',
'Discord Bot setup failed',
error,
)
raise
self.tree.on_error = self.on_app_command_error
async def on_ready(self):
if self._startup_event_sent:
return
self._startup_event_sent = True
await emit_startup_event(self)
async def on_app_command_error(
self,
interaction: discord.Interaction,
error: discord.app_commands.AppCommandError,
):
await emit_command_error(interaction, error)
message = 'コマンド実行中にエラーが発生しました。しばらくしてからもう一度お試しください。'
if interaction.response.is_done():
await interaction.followup.send(message, ephemeral=True)
else:
await interaction.response.send_message(message, ephemeral=True)
async def on_command_error(self, ctx: commands.Context, error: commands.CommandError):
await emit_exception_event(
'command_error',
f'Prefix command failed: {ctx.command}',
error,
actor=str(ctx.author.id) if ctx.author else None,
safe_details={
'command': str(ctx.command),
'guildId': ctx.guild.id if ctx.guild else None,
'channelId': ctx.channel.id if ctx.channel else None,
},
)
await super().on_command_error(ctx, error)
def main():
MyBot().run(TOKEN)
if __name__ == '__main__':
main()