Merge pull request #4 from Androz2091/code-clarifications

Clarify code
This commit is contained in:
Zerio
2020-04-24 16:47:40 +02:00
committed by GitHub
10 changed files with 114 additions and 138 deletions

View File

@@ -1,21 +1,18 @@
const Discord = require("discord.js") const emotes = require ("../config/emojis.json");
const fs = require("fs")
const emotes = require ("../config/emojis.json")
module.exports.run = async (client, message, args) => { module.exports.run = async (client, message) => {
if(!message.member.voice.channel) return message.channel.send(`**You're not in a voice channel ${emotes.error}**`) if(!message.member.voice.channel) return message.channel.send(`**You're not in a voice channel ${emotes.error}**`);
if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`**No music playing on this server ${emotes.error}**`) if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`**No music playing on this server ${emotes.error}**`);
client.player.clearQueue(message.guild.id); client.player.clearQueue(message.guild.id);
message.channel.send(`**Queue cleared ${emotes.success}**`); message.channel.send(`**Queue cleared ${emotes.success}**`);
};
}
module.exports.config = { module.exports.config = {
name: "clear-queue", name: "clear-queue",
aliases: [] aliases: []
} };

View File

@@ -1,21 +1,18 @@
const Discord = require("discord.js") const emotes = require ("../config/emojis.json");
const fs = require("fs")
const emotes = require ("../config/emojis.json")
module.exports.run = async (client, message, args) => { module.exports.run = async (client, message) => {
if(!message.member.voice.channel) return message.channel.send(`**You're not in a voice channel ${emotes.error}**`) if(!message.member.voice.channel) return message.channel.send(`**You're not in a voice channel ${emotes.error}**`);
if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`**No music playing on this server ${emotes.error}**`) if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`**No music playing on this server ${emotes.error}**`);
let song = await client.player.nowPlaying(message.guild.id); const song = await client.player.nowPlaying(message.guild.id);
message.channel.send(`**Currently playing ${song.name} ${emotes.music}**`); message.channel.send(`**Currently playing ${song.name} ${emotes.music}**`);
};
}
module.exports.config = { module.exports.config = {
name: "now-playing", name: "now-playing",
aliases: [] aliases: []
} };

View File

@@ -2,18 +2,17 @@ const Discord = require("discord.js")
const fs = require("fs") const fs = require("fs")
const emotes = require ("../config/emojis.json") const emotes = require ("../config/emojis.json")
module.exports.run = async (client, message, args) => { module.exports.run = async (client, message) => {
if(!message.member.voice.channel) return message.channel.send(`**You're not in a voice channel ${emotes.error}**`) if(!message.member.voice.channel) return message.channel.send(`**You're not in a voice channel ${emotes.error}**`);
let song = await client.player.pause(message.guild.id); if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`**No music playing on this server ${emotes.error}**`);
const song = await client.player.pause(message.guild.id);
if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`**No music playing on this server ${emotes.error}**`)
message.channel.send(`**Song ${song.name} paused ${emotes.success}**`); message.channel.send(`**Song ${song.name} paused ${emotes.success}**`);
};
}
module.exports.config = { module.exports.config = {
name: "pause", name: "pause",

View File

@@ -1,28 +1,27 @@
const Discord = require("discord.js") const emotes = require ("../config/emojis.json");
const fs = require("fs")
const emotes = require ("../config/emojis.json")
module.exports.run = async (client, message, args) => { module.exports.run = async (client, message, args) => {
if(!message.member.voice.channel) return message.channel.send(`**You're not in a voice channel ${emotes.error}**`) if(!message.member.voice.channel) return message.channel.send(`**You're not in a voice channel ${emotes.error}**`);
if (!args[0]) return message.channel.send(`**Please enter a music ${emotes.error}**`) if (!args[0]) return message.channel.send(`**Please enter a music ${emotes.error}**`);
let aSongIsAlreadyPlaying = client.player.isPlaying(message.guild.id); const aSongIsAlreadyPlaying = client.player.isPlaying(message.guild.id);
// If there's already a song playing // If there's already a song playing
if(aSongIsAlreadyPlaying){ if(aSongIsAlreadyPlaying){
// Add the song to the queue // Add the song to the queue
let song = await client.player.addToQueue(message.guild.id, args.join(" ")); const song = await client.player.addToQueue(message.guild.id, args.join(" "));
message.channel.send(`**Song ${song.name} added to queue ${emotes.music}**`); message.channel.send(`**Song ${song.name} added to queue ${emotes.music}**`);
} else { } else {
// Else, play the song // Else, play the song
let song = await client.player.play(message.member.voice.channel, args.join(" ")); const song = await client.player.play(message.member.voice.channel, args.join(" "));
message.channel.send(`**Currently playing ${song.name} ${emotes.music}**`); message.channel.send(`**Currently playing ${song.name} ${emotes.music}**`);
} }
} };
module.exports.config = { module.exports.config = {
name: "play", name: "play",
aliases: [] aliases: []
} };

View File

@@ -1,12 +1,10 @@
const Discord = require("discord.js") const emotes = require ("../config/emojis.json");
const fs = require("fs")
const emotes = require ("../config/emojis.json")
module.exports.run = async (client, message, args) => { module.exports.run = async (client, message) => {
if(!message.member.voice.channel) return message.channel.send(`**You're not in a voice channel ${emotes.error}**`) if(!message.member.voice.channel) return message.channel.send(`**You're not in a voice channel ${emotes.error}**`);
let queue = client.player.getQueue(message.guild.id); const queue = client.player.getQueue(message.guild.id);
if(!queue) return message.channel.send(`**No songs currently playing ${emotes.error}**`); if(!queue) return message.channel.send(`**No songs currently playing ${emotes.error}**`);
@@ -14,10 +12,10 @@ module.exports.run = async (client, message, args) => {
return `${i === 0 ? 'Current' : `#${i+1}`} - ${song.name} | ${song.author}` return `${i === 0 ? 'Current' : `#${i+1}`} - ${song.name} | ${song.author}`
}).join('\n'))); }).join('\n')));
} };
module.exports.config = { module.exports.config = {
name: "queue", name: "queue",
aliases: [] aliases: []
} };

View File

@@ -1,21 +1,18 @@
const Discord = require("discord.js") const emotes = require ("../config/emojis.json");
const fs = require("fs")
const emotes = require ("../config/emojis.json")
module.exports.run = async (client, message, args) => { module.exports.run = async (client, message) => {
if(!message.member.voice.channel) return message.channel.send(`**You're not in a voice channel ${emotes.error}**`) if(!message.member.voice.channel) return message.channel.send(`**You're not in a voice channel ${emotes.error}**`);
let song = await client.player.resume(message.guild.id); const song = await client.player.resume(message.guild.id);
if(!song) return message.channel.send(`**No songs currently playing ${emotes.error}**`); if(!song) return message.channel.send(`**No songs currently playing ${emotes.error}**`);
message.channel.send(`**Song ${song.name} resumed ${emotes.success}**`); message.channel.send(`**Song ${song.name} resumed ${emotes.success}**`);
};
}
module.exports.config = { module.exports.config = {
name: "resume", name: "resume",
aliases: [] aliases: []
} };

View File

@@ -1,23 +1,21 @@
const Discord = require("discord.js") const emotes = require ("../config/emojis.json");
const fs = require("fs")
const emotes = require ("../config/emojis.json")
module.exports.run = async (client, message, args) => { module.exports.run = async (client, message, args) => {
if(!message.member.voice.channel) return message.channel.send(`**You're not in a voice channel ${emotes.error}**`) if(!message.member.voice.channel) return message.channel.send(`**You're not in a voice channel ${emotes.error}**`);
if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`**No music playing on this server ${emotes.error}**`);
if(!args[0]) return message.channel.send(`**Please enter a number ${emotes.error}**`);
if(isNaN(args[0])) return message.channel.send(`**Please enter a valid number ${emotes.error}**`);
if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`**No music playing on this server ${emotes.error}**`)
if (!args[0]) return message.channel.send(`**Please enter a number ${emotes.error}**`)
if (isNaN(args[0])) return message.channel.send(`**Please enter a valid number ${emotes.error}**`)
client.player.setVolume(message.guild.id, parseInt(args.join(" "))); client.player.setVolume(message.guild.id, parseInt(args.join(" ")));
message.channel.send("**Volume set to** `" + args.join(" ") + "`" + `** ** ${emotes.success}`); message.channel.send("**Volume set to** `" + args.join(" ") + "`" + `** ** ${emotes.success}`);
} };
module.exports.config = { module.exports.config = {
name: "set-volume", name: "set-volume",
aliases: [] aliases: []
} };

View File

@@ -1,21 +1,18 @@
const Discord = require("discord.js") const emotes = require ("../config/emojis.json");
const fs = require("fs")
const emotes = require ("../config/emojis.json")
module.exports.run = async (client, message, args) => { module.exports.run = async (client, message) => {
if(!message.member.voice.channel) return message.channel.send(`**You're not in a voice channel ${emotes.error}**`) if(!message.member.voice.channel) return message.channel.send(`**You're not in a voice channel ${emotes.error}**`);
if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`**No music playing on this server ${emotes.error}**`) if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`**No music playing on this server ${emotes.error}**`);
let song = await client.player.skip(message.guild.id); const song = await client.player.skip(message.guild.id);
message.channel.send(`**Song ${song.name} skipped ${emotes.success}**`); message.channel.send(`**Song ${song.name} skipped ${emotes.success}**`);
};
}
module.exports.config = { module.exports.config = {
name: "skip", name: "skip",
aliases: [] aliases: []
} };

View File

@@ -1,21 +1,18 @@
const Discord = require("discord.js") const emotes = require ("../config/emojis.json");
const fs = require("fs")
const emotes = require ("../config/emojis.json")
module.exports.run = async (client, message, args) => { module.exports.run = async (client, message) => {
if(!message.member.voice.channel) return message.channel.send(`**You're not in a voice channel ${emotes.error}**`) if(!message.member.voice.channel) return message.channel.send(`**You're not in a voice channel ${emotes.error}**`);
if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`**No music playing on this server ${emotes.error}**`) if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`**No music playing on this server ${emotes.error}**`);
client.player.stop(message.guild.id); client.player.stop(message.guild.id);
message.channel.send(`**Music stopped ${emotes.success}**`); message.channel.send(`**Music stopped ${emotes.success}**`);
};
}
module.exports.config = { module.exports.config = {
name: "stop", name: "stop",
aliases: [] aliases: []
} };

View File

@@ -1,62 +1,59 @@
const Discord = require("discord.js") const Discord = require("discord.js");
const fs = require("fs") const fs = require("fs");
const client = new Discord.Client() const client = new Discord.Client();
const settings = require ("./config/bot.json") //The bot connects using the configuration file const settings = require ("./config/bot.json") // The bot connects using the configuration file
const emotes = require ("./config/emojis.json") //The bot finds emojis const { Player } = require("discord-player"); // Create a new Player (Youtube API key is your Youtube Data v3 key)
const { Player } = require("discord-player"); //Create a new Player (Youtube API key is your Youtube Data v3 key) const player = new Player(client, settings.youtube_api); // To easily access the player
const player = new Player(client, settings.youtube_api); //To easily access the player
client.player = player; client.player = player;
client.on("ready", () => { client.on("ready", () => {
console.log("The bot is ready to play music"); //If the bot is ready it sends a message in the console console.log("The bot is ready to play music"); // If the bot is ready it sends a message in the console
}); });
client.login(settings.token_bot); //The bot connects thanks to the token client.login(settings.token_bot); //The bot connects thanks to the token
client.on('message', async message => { client.on('message', async (message) => {
let prefix = settings.prefix const prefix = settings.prefix;
let messageArray = message.content.split(" ") const messageArray = message.content.split(" ");
let cmd = messageArray[0].toLowerCase(); const cmd = messageArray[0].toLowerCase();
let args = messageArray.slice(1); const args = messageArray.slice(1);
if(!message.content.startsWith(prefix)) return; if(!message.content.startsWith(prefix)) return;
let commandfile = client.commands.get(cmd.slice(prefix.length)) || client.commands.get(client.aliases.get(cmd.slice(prefix.length))) 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) if(commandfile) commandfile.run(client,message,args)
});
client.commands = new Discord.Collection();
}) client.aliases = new Discord.Collection();
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
fs.readdir("./commands/", (err, files) => { fs.readdir("./commands/", (err, files) => {
let jsfile = files.filter(f => f.split(".").pop() === "js") const jsfiles = files.filter(f => f.split(".").pop() === "js")
if(jsfile.length <= 0) { if(jsfiles.length <= 0) {
return console.log("Couldn't Find Commands !"); return console.log("Couldn't find any commands!");
} }
jsfile.forEach((f, i) => { jsfiles.forEach((file) => {
console.log(`Run command ${f}`); console.log(`Loading command ${file}`);
let pull = require(`./commands/${f}`); const command = require(`./commands/${file}`);
client.commands.set(command.config.name, command);
command.config.aliases.forEach(alias => {
client.aliases.set(alias, command.config.name);
});
client.commands.set(pull.config.name, pull);
pull.config.aliases.forEach(alias => {
client.aliases.set(alias, pull.config.name)
}); });
})});
});