-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
slash.interactionCreate.native.ts
73 lines (62 loc) · 1.9 KB
/
slash.interactionCreate.native.ts
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
// system file, please don't modify it
import * as app from "#app"
export default new app.Listener({
event: "interactionCreate",
description: "Handle the interactions for slash commands",
async run(interaction) {
if (!interaction.isChatInputCommand()) return
if (!app.cache.ensure<boolean>("turn", true)) return
const cmd = app.slashCommands.get(interaction.commandName)
if (!cmd)
return interaction.reply(
await app.getSystemMessage("error", "Command not found"),
)
try {
await app.prepareSlashCommand(interaction, cmd)
} catch (error) {
if (error instanceof Error) {
if (!(error instanceof app.SlashCommandError))
app.error(error, cmd.filepath!, true)
return interaction.reply(await app.getSystemMessage("error", error))
} else {
return interaction.reply(
await app.getSystemMessage(
"error",
"An unknown error while preparing the command",
),
)
}
}
try {
await cmd.options.run.bind(interaction)(interaction)
} catch (error: unknown) {
let errorMessage: app.SystemMessage
if (error instanceof Error) {
app.error(error, cmd.filepath!, true)
errorMessage = await app.getSystemMessage("error", error, {
stack: true,
})
} else {
errorMessage = await app.getSystemMessage(
"error",
"An unknown error while executing the command",
)
}
if (interaction.replied || interaction.deferred) {
interaction[interaction.replied ? "followUp" : "editReply"]({
...errorMessage,
ephemeral: true,
})
} else {
interaction
.reply({
...errorMessage,
ephemeral: true,
})
.catch((error) => {
app.error(error, cmd!.filepath!, true)
})
}
}
},
})