-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.ts
More file actions
65 lines (50 loc) · 1.92 KB
/
bot.ts
File metadata and controls
65 lines (50 loc) · 1.92 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
import { Client } from 'discord.js';
import { loadKeyedWeights, loadWeights } from './util/data';
import commandList, { serverCommands } from './commands';
import { servers } from './config';
const weights = Object.fromEntries(servers.map((id) => [id, {
foWeights: loadWeights('first_ord_words', id),
soWeights: loadWeights('second_ord_words', id),
foKeyedWeights: loadKeyedWeights('first_ord_words', id),
soKeyedWeights: loadKeyedWeights('second_ord_words', id)
}]))
export type ServerWeights = typeof weights[string];
const client = new Client({
intents: [
"Guilds",
"GuildMessages",
"GuildPresences",
"GuildMembers",
"GuildMessageReactions",
"MessageContent"
],
// presence: { activities: [{ type: ActivityType.Watching, name: 'y\'all 🥰' }] },
allowedMentions: { repliedUser: false }
});
const commands = Object.fromEntries(commandList.concat(serverCommands).map((c) => [c.data.name, c]))
client.once('clientReady', async () => {
console.log(`Logged in as ${client.user?.tag}!`);
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isChatInputCommand()) return;
const raw = commands[interaction.commandName];
if (!raw) return;
const command = 'commands' in raw
? raw.commands[interaction.options.getSubcommand()]
: raw
if (!command) return;
const d = weights[interaction.guildId!];
await command.execute(interaction, d);
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isAutocomplete()) return;
const raw = commands[interaction.commandName];
if (!raw) return;
const command = 'commands' in raw
? raw.commands[interaction.options.getSubcommand()]
: raw
if (!command?.autocomplete) return;
const d = weights[interaction.guildId!];
await command.autocomplete(interaction, d);
})
void client.login(process.env.TOKEN);