-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
45 lines (37 loc) · 1.56 KB
/
index.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
import { Client, Events, InteractionType, TextBasedChannel } from 'discord.js'
import Commands from './src/commands'
import Database from './src/utils/database'
import Monitors from './src/utils/monitors'
import { Connection } from './src/classes/connection'
const client = new Client({ intents: ['Guilds'] })
const CONFIG = require('./config/config.json')
client.on(Events.ClientReady, async () => {
Database.migrate()
Commands.init(client)
// Reconnect to all monitors
const connections: Connection[] = await Database.getConnections()
connections.forEach((result: any) => Monitors.make(result, client))
})
client.on(Events.InteractionCreate, async (interaction) => {
switch (interaction.type) {
case InteractionType.ApplicationCommandAutocomplete: // Auto complete interaction
Commands.Autocomplete(interaction)
break
case InteractionType.ApplicationCommand: // Slash command interaction
Commands.Execute(interaction)
Database.createLog(interaction.guildId || '0', interaction.user.id, `Executed command ${interaction.commandName}`)
break
}
})
client.on(Events.GuildCreate, async (guild) => {
// Add the guild to the database
await Database.createLog(guild.id, '0', 'Added to guild')
// Document to the logs channel
const channel = client.channels.cache.get(CONFIG.logs.channel) as TextBasedChannel
channel.send(`Added to guild ${guild.name}`)
})
client.on(Events.GuildDelete, async (guild) => {
// Remove the guild from the database
await Database.createLog(guild.id, '0', 'Removed from guild')
})
client.login(CONFIG.token)