forked from LAION-AI/Open-Assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.ts
48 lines (44 loc) · 1.21 KB
/
commands.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
import { Events } from "discord.js";
const interactionType = {
type: "interaction",
load: async (interaction) => {
await interaction.deferReply();
},
reply: async (interaction, content) => {
if (interaction.deferred || interaction.replied) {
await interaction.editReply(content);
} else {
await interaction.reply(content);
}
},
};
export default {
name: Events.InteractionCreate,
once: false,
async execute(interaction, client) {
if (
!interaction.isChatInputCommand() &&
!interaction.isContextMenuCommand()
)
return;
var commands = await client.commands.toJSON();
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(
`No command matching ${interaction.commandName} was found.`
);
return;
}
var guildId;
if (interaction.guild) guildId = interaction.guild.id;
try {
await command.execute(interaction, client, commands, interactionType);
} catch (error) {
console.log(error);
await interactionType.reply(interaction, {
content: "There was an error while executing this command!",
ephemeral: true,
});
}
},
};