-
Notifications
You must be signed in to change notification settings - Fork 17
/
app.js
47 lines (39 loc) · 1.59 KB
/
app.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
const { Client, GatewayIntentBits, Collection } = require('discord.js')
const fs = require('fs')
const path = require('path')
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates] })
const { Player } = require('discord-player')
const { config } = require('dotenv')
const { YouTubeExtractor, AttachmentExtractor } = require("@discord-player/extractor");
config({
path: `${__dirname}/.env`
});
const token = process.env.TOKEN;
client.commands = new Collection();
client.function = require('./Utils/functions.js')
const player = new Player(client)
player.extractors.register(YouTubeExtractor);
player.extractors.register(AttachmentExtractor);
require(`./Utils/cmdHandler`)(client)
const eventsPath = path.join(__dirname, 'events')
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'))
const playerEventsPath = path.join(__dirname, 'playerEvents')
const playerEventFiles = fs.readdirSync(playerEventsPath).filter(file => file.endsWith('.js'))
for (const file of eventFiles) {
const filePath = path.join(eventsPath, file)
const event = require(filePath)
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client))
} else {
client.on(event.name, (...args) => event.execute(...args, client, player))
}
}
for (const file of playerEventFiles) {
const filePath = path.join(playerEventsPath, file)
const playerEvent = require(filePath)
player.events.on(playerEvent.name, async (...args) => playerEvent.execute(...args, client))
}
client.login(token)
process.on("unhandledRejection", (err) => {
console.error(err)
});