74 lines
2.6 KiB
JavaScript
Executable File
74 lines
2.6 KiB
JavaScript
Executable File
// PACKAGES
|
|
const fs = require('fs')
|
|
const { Client, Collection, GatewayIntentBits, REST, Routes } = require('discord.js')
|
|
const { Player } = require('discord-player')
|
|
const { YouTubeExtractor, SpotifyExtractor } = require('@discord-player/extractor')
|
|
require('dotenv').config()
|
|
|
|
|
|
// CLIENT INITIALIZATION
|
|
let intents = [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildVoiceStates]
|
|
const client = new Client({ intents })
|
|
|
|
|
|
// EVENTS HANDLING
|
|
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'))
|
|
for (file of eventFiles) {
|
|
let event = require(`./events/${file}`)
|
|
if (event.once) client.once(event.name, (...args) => { event.execute(...args) })
|
|
else client.on(event.name, (...args) => { event.execute(...args) })
|
|
}
|
|
|
|
|
|
// COMMANDS HANDLING
|
|
client.commands = new Collection()
|
|
let commands = []
|
|
|
|
const commandFolders = fs.readdirSync('./commands')
|
|
for (folder of commandFolders) {
|
|
let folderPath = `./commands/${folder}`
|
|
let commandFiles = fs.readdirSync(folderPath).filter(file => file.endsWith('.js'))
|
|
for (file of commandFiles) {
|
|
let command = require(`${folderPath}/${file}`)
|
|
if ('data' in command && 'execute' in command) { commands.push(command.data.toJSON()); client.commands.set(command.data.name, command) }
|
|
else console.log(`\u001b[1;35m [WARNING] The command at ${`${folderPath}/${file}`} is missing a required "data" or "execute" property.`)
|
|
}
|
|
}
|
|
|
|
|
|
// COMMANDS REGISTERING
|
|
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN);
|
|
(async () => {
|
|
try { await rest.put(Routes.applicationCommands(process.env.DISCORD_APP_ID), { body: commands }) }
|
|
catch (error) { console.error(error) }
|
|
})()
|
|
|
|
|
|
// BUTTONS HANDLING
|
|
client.buttons = new Collection()
|
|
|
|
const buttonFiles = fs.readdirSync('./buttons').filter(file => file.endsWith('.js'))
|
|
for (file of buttonFiles) {
|
|
let button = require(`./buttons/${file}`)
|
|
if ('id' in button && 'execute' in button) client.buttons.set(button.id, button)
|
|
else console.log(`\u001b[1;35m [WARNING] The button ${file} is missing a required "id" or "execute" property.`)
|
|
}
|
|
|
|
|
|
// PLAYER INITIALIZATION
|
|
const player = new Player(client, { autoRegisterExtractor: false })
|
|
player.extractors.register(YouTubeExtractor)
|
|
player.extractors.register(SpotifyExtractor)
|
|
|
|
|
|
// PLAYER EVENTS HANDLING
|
|
const eventPlayerFiles = fs.readdirSync('./eventsPlayer').filter(file => file.endsWith('.js'))
|
|
for (file of eventPlayerFiles) {
|
|
let event = require(`./eventsPlayer/${file}`)
|
|
if (['debug'].includes(event.name)) continue
|
|
player.events.on(event.name, (...args) => event.execute(...args))
|
|
}
|
|
|
|
|
|
// LAUNCH
|
|
client.login() |