/
server.ts
134 lines (95 loc) · 3.47 KB
/
server.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import * as dotenv from "dotenv";
dotenv.config();
import { Client, Events, GatewayIntentBits } from "discord.js";
const create = require("./commands/create");
const list = require("./commands/list");
const del = require("./commands/delete"); // yoyakugo datta
const edit = require("./commands/edit");
const client: Client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
client.once(Events.ClientReady, () => {
console.log("Ready");
});
// slash commands
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return; // isSlashCommand
if (interaction.commandName === create.data.name) {
try {
await create.execute(interaction);
}
catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: "返信または応答準備中にエラーが発生しました", ephemeral: true });
}
else {
await interaction.reply({ content: "何もできませんでした", ephemeral: true });
}
}
}
else if (interaction.commandName === list.data.name) {
try {
await list.execute(interaction);
}
catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: "返信または応答準備中にエラーが発生しました", ephemeral: true });
}
else {
await interaction.reply({ content: "何もできませんでした", ephemeral: true });
}
}
}
else if (interaction.commandName === del.data.name) {
try {
await del.execute(interaction);
}
catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: "返信または応答準備中にエラーが発生しました", ephemeral: true });
}
else {
await interaction.reply({ content: "何もできませんでした", ephemeral: true });
}
}
}
else if (interaction.commandName === edit.data.name) {
try {
await edit.execute(interaction);
}
catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: "返信または応答準備中にエラーが発生しました", ephemeral: true });
}
else {
await interaction.reply({ content: "何もできませんでした", ephemeral: true });
}
}
}
else {
console.error(`${interaction.commandName} is not found`);
}
});
// create (modal)
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isModalSubmit()) return;
if (interaction.customId === "create") {
try {
await create.modal(interaction);
}
catch (error) {
console.error(error);
}
}
if (interaction.customId === "edit") {
try {
await edit.modal(interaction);
}
catch (error) {
console.error(error);
}
}
});
client.login(process.env.token!);