forked from BluDood/BluBot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
67 lines (55 loc) · 2.38 KB
/
index.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
const { Client, Collection, GatewayIntentBits, Events } = require('discord.js')
const fs = require('fs')
const deploy = require('./utils/deploy')
const con = require('./utils/console')
const { cacheAll } = require('./utils/reactionroles')
const config = require('./utils/config')
const release = require('./utils/release')
const { token } = config.get()
if (!fs.existsSync('./databases')) fs.mkdirSync('./databases')
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildMembers]
})
client.commands = new Collection()
client.modals = new Collection()
client.autoComplete = new Collection()
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'))
const modalFiles = fs.readdirSync('./modals').filter(file => file.endsWith('.js'))
const autoCompleteFiles = fs.readdirSync('./autocomplete').filter(file => file.endsWith('.js'))
for (const file of commandFiles) {
const command = require(`./commands/${file}`)
client.commands.set(command.data.name, command)
}
for (const file of modalFiles) {
const modal = require(`./modals/${file}`)
client.modals.set(modal.id, modal)
}
for (const file of autoCompleteFiles) {
const autoComplete = require(`./autocomplete/${file}`)
client.autoComplete.set(autoComplete.id, autoComplete)
}
for (const eventFile of fs.readdirSync('./events').filter(file => file.endsWith('.js'))) {
const event = require(`./events/${eventFile}`)
client.on(event.event, event.listener)
}
con.init()
client.once(Events.ClientReady, async c => {
con.motd(c.user.tag)
deploy(c.user.id)
cacheAll(client)
release.startCheckLoop(client)
})
client.on(Events.Error, err => console.error(err))
client.on(Events.InteractionCreate, async interaction => {
if (interaction.isCommand()) {
const command = client.commands.get(interaction.commandName)
if (command) await command.execute(interaction).catch(console.error)
} else if (interaction.isModalSubmit()) {
const modal = client.modals.get(interaction.customId)
if (modal) await modal.execute(interaction).catch(console.error)
} else if (interaction.isAutocomplete()) {
const autoComplete = client.autoComplete.get(interaction.commandName)
if (autoComplete) await autoComplete.execute(interaction).catch(console.error)
}
})
client.login(token)