forked from commandblockguy/EigenBot
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
52 lines (47 loc) · 1.57 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
import fs from 'fs'
import {Client} from 'discord.js'
import {REST} from '@discordjs/rest'
import {GatewayIntentBits, Routes} from 'discord-api-types/v10'
const config = JSON.parse(fs.readFileSync('./config.json'))
const client = new Client({intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.MessageContent]})
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`)
// Set the presence for the bot (Listening to !help)
client.user.setPresence({
status: 'online',
activities: [{
name: config.prefix + 'help',
type: 'LISTENING'
}]
})
})
;(async () => {
const commands = []
for (const module in config.modules) {
const modConfig = config.modules[module]
if (!modConfig) continue
if (!fs.existsSync('./modules/' + module + '/index.js')) continue
const m = await import('./modules/' + module + '/index.js')
const moduleCommands = (await m.default(client, config, modConfig)) || []
for (const command of moduleCommands) {
if (command.toJSON) {
commands.push(command.toJSON())
} else {
commands.push(command)
}
}
}
if (!commands.length) return
const rest = new REST({version: '9'}).setToken(config.token)
client.on('ready', () => {
const clientId = client.application.id
rest.put(
config.guild
? Routes.applicationGuildCommands(clientId, config.guild)
: Routes.applicationCommands(clientId),
{body: commands}
)
})
// Login with token
client.login(config.token)
})()