Création Repo pour mon bot Le Tamiseur
This commit is contained in:
74
app.js
Executable file
74
app.js
Executable file
@@ -0,0 +1,74 @@
|
||||
// PACKAGES AND VARIABLES
|
||||
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()
|
||||
|
||||
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 (const file of eventFiles) {
|
||||
let event = require(`./events/${file}`)
|
||||
if (event.once) client.once(event.name, (...args) => {
|
||||
//console.log(`\u001b[1;35m Event '${event.name}' executed.`)
|
||||
event.execute(...args)
|
||||
})
|
||||
else client.on(event.name, (...args) => {
|
||||
//console.log(`\u001b[1;35m Event '${event.name}' executed.`)
|
||||
event.execute(...args)
|
||||
})
|
||||
}
|
||||
|
||||
// COMMANDS HANDLING
|
||||
client.commands = new Collection()
|
||||
let commands = []
|
||||
let 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 () => {
|
||||
//console.log(`\u001b[1;35m Started refreshing ${commands.length} application (/) commands.`)
|
||||
try {
|
||||
let data = await rest.put(Routes.applicationCommands('1065047326860783636'), { body: commands })
|
||||
//console.log(`\u001b[1;35m Successfully reloaded ${data.length} application (/) commands.`)
|
||||
}
|
||||
catch (error) { console.error(error) }
|
||||
})()
|
||||
|
||||
// BUTTONS HANDLING
|
||||
client.buttons = new Collection()
|
||||
let buttonFiles = fs.readdirSync('./buttons').filter(file => file.endsWith('.js'))
|
||||
for (const 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 (const file of eventPlayerFiles) {
|
||||
let event = require(`./eventsPlayer/${file}`)
|
||||
if (['debug'].includes(event.name)) continue
|
||||
player.events.on(event.name, (...args) => event.execute(...args))
|
||||
}
|
||||
//player.on('debug', async (message) => { console.log(`General player debug event: ${message}`) })
|
||||
|
||||
// LAUNCH
|
||||
client.login()
|
||||
Reference in New Issue
Block a user