-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
67 lines (57 loc) · 1.76 KB
/
main.js
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
import { Client, Events, GatewayIntentBits } from 'discord.js';
import { promises as fs } from 'fs';
import * as oversett from './commands/omset.js';
import * as ordbok from './commands/ordbok.js';
import * as bøying from './commands/bøying.js';
const token =
process.env.DISCORD_TOKEN?.trim() ||
(await fs.readFile('./token.txt', 'utf8')).trim();
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
});
/** @type {{ [key: string]: import('discord.js').ApplicationCommand }} */
const commands = {};
client.once(Events.ClientReady, (readyClient) => {
console.log(`Klart til å køyra som ${readyClient.user.tag}!`);
Object.assign(
commands,
oversett.register(readyClient),
ordbok.register(readyClient),
bøying.register(readyClient)
);
});
client.on(Events.ClientError, console.error);
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand()) return;
const command = commands[interaction.commandName];
if (!command) {
console.error(`Ingenting fann for kommandoen ${interaction.commandName}`);
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
try {
if (interaction.replied || interaction.deferred) {
await interaction.followUp({
content: 'Det skjedde ein feil under køyring av denne kommandoen!',
ephemeral: true,
});
} else {
await interaction.reply({
content: 'Det skjedde ein feil under køyring av denne kommandoen!',
ephemeral: true,
});
}
} catch (err) {
console.error(err);
}
}
});
client.login(token);
// Catch CTRL+C
process.on('SIGINT', () => {
client.destroy();
process.exit(0);
});