🎉 New version
This commit is contained in:
77
index.js
77
index.js
@@ -1,59 +1,46 @@
|
|||||||
|
//Modules
|
||||||
const Discord = require("discord.js");
|
const Discord = require("discord.js");
|
||||||
|
const Enmap = require('enmap')
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
|
//New client
|
||||||
const client = new Discord.Client();
|
const client = new Discord.Client();
|
||||||
|
|
||||||
const settings = require ("./config/bot.json") // The bot connects using the configuration file
|
//The bot connects using the configuration file
|
||||||
|
const settings = require ("./config/bot.json")
|
||||||
|
|
||||||
const { Player } = require("discord-player"); // Create a new Player (Youtube API key is your Youtube Data v3 key)
|
//Create a new Player
|
||||||
|
const { Player } = require("discord-player")
|
||||||
const player = new Player(client, settings.youtube_api); // To easily access the player
|
|
||||||
|
|
||||||
|
//To easily access the player
|
||||||
|
const player = new Player(client)
|
||||||
client.player = player;
|
client.player = player;
|
||||||
|
|
||||||
client.on("ready", () => {
|
//Events
|
||||||
|
fs.readdir("./events/", (err, files) => {
|
||||||
console.log("The bot is ready to play music"); // If the bot is ready it sends a message in the console
|
if (err) return console.error(err);
|
||||||
|
files.forEach(file => {
|
||||||
|
const event = require(`./events/${file}`);
|
||||||
|
let eventName = file.split(".")[0];
|
||||||
|
console.log(`Loading event ${eventName}`);
|
||||||
|
client.on(eventName, event.bind(null, client));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
client.login(settings.token_bot); //The bot connects thanks to the token
|
//New commands
|
||||||
|
client.commands = new Enmap();
|
||||||
client.on('message', async (message) => {
|
|
||||||
|
|
||||||
const prefix = settings.prefix;
|
|
||||||
|
|
||||||
const messageArray = message.content.split(" ");
|
|
||||||
const cmd = messageArray[0].toLowerCase();
|
|
||||||
const args = messageArray.slice(1);
|
|
||||||
|
|
||||||
if(!message.content.startsWith(prefix)) return;
|
|
||||||
const commandfile = client.commands.get(cmd.slice(prefix.length)) || client.commands.get(client.aliases.get(cmd.slice(prefix.length)))
|
|
||||||
if(commandfile) commandfile.run(client,message,args)
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
client.commands = new Discord.Collection();
|
|
||||||
client.aliases = new Discord.Collection();
|
|
||||||
|
|
||||||
|
//Commands
|
||||||
fs.readdir("./commands/", (err, files) => {
|
fs.readdir("./commands/", (err, files) => {
|
||||||
|
if (err) return console.error(err);
|
||||||
const jsfiles = files.filter(f => f.split(".").pop() === "js")
|
files.forEach(file => {
|
||||||
|
if (!file.endsWith(".js")) return;
|
||||||
if(jsfiles.length <= 0) {
|
let props = require(`./commands/${file}`);
|
||||||
return console.log("Couldn't find any commands!");
|
let commandName = file.split(".")[0];
|
||||||
}
|
console.log(`Loading command ${commandName}`);
|
||||||
|
client.commands.set(commandName, props);
|
||||||
jsfiles.forEach((file) => {
|
|
||||||
|
|
||||||
console.log(`Loading command ${file}`);
|
|
||||||
|
|
||||||
const command = require(`./commands/${file}`);
|
|
||||||
|
|
||||||
client.commands.set(command.config.name, command);
|
|
||||||
command.config.aliases.forEach(alias => {
|
|
||||||
client.aliases.set(alias, command.config.name);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Login
|
||||||
|
client.login(settings.token_bot);
|
||||||
|
|||||||
Reference in New Issue
Block a user