diff --git a/.gitignore b/.gitignore index abd417b..ac059c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ # Node -node_modules/ - +node_modules/ \ No newline at end of file diff --git a/README.md b/README.md index f93aabf..178facc 100644 --- a/README.md +++ b/README.md @@ -8,38 +8,38 @@ If you need help with this project, to get support faster you can join the help ### ⚡ Installation Well, let's start by downloading the code. -Go to the folder `config` then the file `bot.json`. +Go to the folder `config` then the file `bot.js`. For the bot to be able to start, please complete the file with your credentials as follows : +- For emojis + ```js -{ - "game": "GAME", - "prefix": "PREFIX", - "token_bot": "TOKEN" +emojis: { + off: ':x:', + error: ':warning:', + queue: ':bar_chart:', + music: ':musical_note:', + success: ':white_check_mark:', } ``` -Reminder : +- For configuration -- `game`, the status of the bot. +```js +discord: { + token: 'TOKEN', + prefix: 'PREFIX', + activity: 'ACTIVITY', +} +``` + +- `token`, the token of the bot available on the [Discord Developers](https://discordapp.com/developers/applications) section. - `prefix`, the prefix that will be set to use the bot. -- `token_bot`, the token of the bot available on the [Discord Developers](https://discordapp.com/developers/applications) section. - -To customize the emojis go to the file `emojis.json` in the same folder. -Emojis are already defined by default but you can modify them if you wish. - -```js -{ - "music": ":musical_note:", - "queue": ":bar_chart:", - "error": ":x:", - "success": ":white_check_mark:" -} -``` +- `activity`, the activity of the bot. In the console, type `npm install` to install all dependencies. -To start the bot : +- To start the bot : ``` #With Node @@ -81,4 +81,4 @@ debug, see number of voice connections. Find all the functions available on the official code [right here](https://github.com/Androz2091/discord-player). -This is used with [discord.js](https://www.npmjs.com/package/discord.js) and [discord-player](https://www.npmjs.com/package/discord-player). +This is used with [discord.js](https://www.npmjs.com/package/discord.js) and [discord-player](https://www.npmjs.com/package/discord-player). \ No newline at end of file diff --git a/commands/core/help.js b/commands/core/help.js index a9d608f..7591865 100644 --- a/commands/core/help.js +++ b/commands/core/help.js @@ -20,7 +20,7 @@ module.exports = { { name: 'Filters', value: '`bassboost`, `8D`, `vaporwave`, `nightcore`, `phaser`, `tremolo`, `vibrato`, `reverse`, `treble`, `normalizer`, `surrounding`, `pulsator`, `subboost`, `karaoke`, `flanger`, `gate`, `haas`, `mcompand`' }, ], timestamp: new Date(), - description: `To use filters, ${client.config.prefix}filter (the filter). Example : ${client.config.prefix}filter 8D.`, + description: `To use filters, ${client.config.discord.prefix}filter (the filter). Example : ${client.config.discord.prefix}filter 8D.`, }, }); } else { @@ -37,7 +37,7 @@ module.exports = { { name: 'Name', value: command.name, inline: true }, { name: 'Category', value: command.category, inline: true }, { name: 'Aliase(s)', value: command.aliases.length < 1 ? 'None' : command.aliases.join('\n'), inline: true }, - { name: 'Utilisation', value: command.utilisation.replace('{prefix}', client.config.prefix), inline: true }, + { name: 'Utilisation', value: command.utilisation.replace('{prefix}', client.config.discord.prefix), inline: true }, ], timestamp: new Date(), description: 'Find information on the command provided.\nMandatory arguments `[]`, optional arguments `<>`.', diff --git a/commands/infos/debug.js b/commands/infos/debug.js index d90de6d..fb0be53 100644 --- a/commands/infos/debug.js +++ b/commands/infos/debug.js @@ -5,6 +5,6 @@ module.exports = { utilisation: '{prefix}debug', execute(client, message) { - message.channel.send(`${client.emotes.success} - Robot connected in **${client.voice.connections.size}** channels !`); + message.channel.send(`${client.emotes.success} - ${client.user.username} connected in **${client.voice.connections.size}** channels !`); }, }; \ No newline at end of file diff --git a/commands/music/filter.js b/commands/music/filter.js index d9f00c7..b82a692 100644 --- a/commands/music/filter.js +++ b/commands/music/filter.js @@ -13,18 +13,17 @@ module.exports = { if (!args[0]) return message.channel.send(`${client.emotes.error} - Please specify a valid filter to enable or disable !`); - const filterToUpdate = Object.values(client.filters).find((f) => f.toLowerCase() === args[0].toLowerCase()); + const filterToUpdate = client.filters.find((x) => x.toLowerCase() === args[0].toLowerCase()); - if (!filterToUpdate) return message.channel.send(`${client.emotes.error} - This filter doesn't exist !`); + if (!filterToUpdate) return message.channel.send(`${client.emotes.error} - This filter doesn't exist, try for example (8D, vibrato, pulsator...) !`); - const filterRealName = Object.keys(client.filters).find((f) => client.filters[f] === filterToUpdate); - - const queueFilters = client.player.getQueue(message).filters; const filtersUpdated = {}; - filtersUpdated[filterRealName] = queueFilters[filterRealName] ? false : true; + + filtersUpdated[filterToUpdate] = client.player.getQueue(message).filters[filterToUpdate] ? false : true; + client.player.setFilters(message, filtersUpdated); - if (filtersUpdated[filterRealName]) message.channel.send(`${client.emotes.music} - I'm **adding** the filter to the music, please wait... Note : the longer the music is, the longer this will take.`); + if (filtersUpdated[filterToUpdate]) message.channel.send(`${client.emotes.music} - I'm **adding** the filter to the music, please wait... Note : the longer the music is, the longer this will take.`); else message.channel.send(`${client.emotes.music} - I'm **disabling** the filter on the music, please wait... Note : the longer the music is playing, the longer this will take.`); }, }; \ No newline at end of file diff --git a/commands/music/nowplaying.js b/commands/music/nowplaying.js index 71c5d20..4acac1c 100644 --- a/commands/music/nowplaying.js +++ b/commands/music/nowplaying.js @@ -14,9 +14,7 @@ module.exports = { const track = client.player.nowPlaying(message); const filters = []; - Object.keys(client.player.getQueue(message).filters).forEach((filterName) => { - if (client.player.getQueue(message).filters[filterName]) filters.push(filterName); - }); + Object.keys(client.player.getQueue(message).filters).forEach((filterName) => client.player.getQueue(message).filters[filterName]) ? filters.push(filterName) : false; message.channel.send({ embed: { @@ -30,7 +28,7 @@ module.exports = { { name: 'Views', value: track.views, inline: true }, { name: 'Duration', value: track.duration, inline: true }, - { name: 'Filters activated', value: filters.length, inline: true }, + { name: 'Filters activated', value: filters.length + '/' + client.filters.length, inline: true }, { name: 'Volume', value: client.player.getQueue(message).volume, inline: true }, { name: 'Repeat mode', value: client.player.getQueue(message).repeatMode ? 'Yes' : 'No', inline: true }, diff --git a/commands/music/pause.js b/commands/music/pause.js index dbfc2d3..8a44400 100644 --- a/commands/music/pause.js +++ b/commands/music/pause.js @@ -15,6 +15,6 @@ module.exports = { client.player.pause(message); - message.channel.send(`${client.emotes.success} - Song ${client.player.getQueue(message).playing.title} **paused** !`); + message.channel.send(`${client.emotes.success} - Song ${client.player.getQueue(message).playing.title} paused !`); }, }; \ No newline at end of file diff --git a/commands/music/resume.js b/commands/music/resume.js index 548009f..e3c0000 100644 --- a/commands/music/resume.js +++ b/commands/music/resume.js @@ -15,6 +15,6 @@ module.exports = { client.player.resume(message); - message.channel.send(`${client.emotes.success} - Song ${client.player.getQueue(message).playing.title} **resumed** !`); + message.channel.send(`${client.emotes.success} - Song ${client.player.getQueue(message).playing.title} resumed !`); }, }; \ No newline at end of file diff --git a/commands/music/w-filters.js b/commands/music/w-filters.js index 20bd798..4771846 100644 --- a/commands/music/w-filters.js +++ b/commands/music/w-filters.js @@ -11,14 +11,11 @@ module.exports = { if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`); - const disabledEmoji = client.emotes.error; - const enabledEmoji = client.emotes.success; - const filtersStatuses = [[], []]; - Object.keys(client.filters).forEach((filterName) => { + client.filters.forEach((filterName) => { const array = filtersStatuses[0].length > filtersStatuses[1].length ? filtersStatuses[1] : filtersStatuses[0]; - array.push(client.filters[filterName] + " : " + (client.player.getQueue(message).filters[filterName] ? enabledEmoji : disabledEmoji)); + array.push(filterName.charAt(0).toUpperCase() + filterName.slice(1) + " : " + (client.player.getQueue(message).filters[filterName] ? client.emotes.success : client.emotes.off)); }); message.channel.send({ @@ -30,7 +27,7 @@ module.exports = { { name: '** **', value: filtersStatuses[1].join('\n'), inline: true }, ], timestamp: new Date(), - description: `List of all filters enabled or disabled.\nUse \`${client.config.prefix}filter\` to add a filter to a song.`, + description: `List of all filters enabled or disabled.\nUse \`${client.config.discord.prefix}filter\` to add a filter to a song.`, }, }); }, diff --git a/config/bot.js b/config/bot.js new file mode 100644 index 0000000..f504a11 --- /dev/null +++ b/config/bot.js @@ -0,0 +1,17 @@ +module.exports = { + emojis: { + off: ':x:', + error: ':warning:', + queue: ':bar_chart:', + music: ':musical_note:', + success: ':white_check_mark:', + }, + + discord: { + token: 'TOKEN', + prefix: 'PREFIX', + activity: 'ACTIVITY', + }, + + filters: ['8D', 'gate', 'haas', 'phaser', 'treble', 'tremolo', 'vibrato', 'reverse', 'karaoke', 'flanger', 'mcompand', 'pulsator', 'subboost', 'bassboost', 'vaporwave', 'nightcore', 'normalizer', 'surrounding'], +}; \ No newline at end of file diff --git a/config/bot.json b/config/bot.json deleted file mode 100644 index 2cdaa91..0000000 --- a/config/bot.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "game": "GAME", - "prefix": "PREFIX", - "token_bot": "TOKEN" -} \ No newline at end of file diff --git a/config/emojis.json b/config/emojis.json deleted file mode 100644 index 70efdbd..0000000 --- a/config/emojis.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "music": ":musical_note:", - "queue": ":bar_chart:", - "error": ":x:", - "success": ":white_check_mark:" -} diff --git a/config/filters.json b/config/filters.json deleted file mode 100644 index 1a2732f..0000000 --- a/config/filters.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "bassboost": "Bassboost", - "8D": "8D", - "vaporwave": "Vaporwave", - "nightcore": "Nightcore", - "phaser": "Phaser", - "tremolo": "Tremolo", - "vibrato": "Vibrato", - "reverse": "Reverse", - "treble": "Treble", - "normalizer": "Normalizer", - "surrounding": "Surrounding", - "pulsator": "Pulsator", - "subboost": "Subboost", - "karaoke": "Karaoke", - "flanger": "Flanger", - "gate": "Gate", - "haas": "Haas", - "mcompand": "Mcompand" -} diff --git a/events/message.js b/events/message.js index 9ba5fb3..5c685af 100644 --- a/events/message.js +++ b/events/message.js @@ -1,8 +1,7 @@ module.exports = (client, message) => { + if (message.author.bot || message.channel.type === 'dm') return; - if (message.author.bot) return; - - const prefix = client.config.prefix; + const prefix = client.config.discord.prefix; if (message.content.indexOf(prefix) !== 0) return; @@ -12,5 +11,4 @@ module.exports = (client, message) => { const cmd = client.commands.get(command) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(command)); if (cmd) cmd.execute(client, message, args); - }; \ No newline at end of file diff --git a/events/ready.js b/events/ready.js index 2716426..bc00202 100644 --- a/events/ready.js +++ b/events/ready.js @@ -1,7 +1,5 @@ module.exports = async (client) => { - console.log(`Ready on ${client.guilds.cache.size} servers, for a total of ${client.users.cache.size} users`); - client.user.setActivity(client.config.game); - + client.user.setActivity(client.config.discord.activity); }; \ No newline at end of file diff --git a/index.js b/index.js index 517ec9c..f5c3c9c 100644 --- a/index.js +++ b/index.js @@ -6,32 +6,20 @@ const client = new discord.Client({ disableMentions: 'everyone' }); const { Player } = require('discord-player'); client.player = new Player(client); -client.config = require('./config/bot.json'); -client.emotes = require('./config/emojis.json'); -client.filters = require('./config/filters.json'); +client.config = require('./config/bot'); +client.emotes = client.config.emojis; +client.filters = client.config.filters; client.commands = new discord.Collection(); -const core = fs.readdirSync('./commands/core').filter(file => file.endsWith('.js')); -const infos = fs.readdirSync('./commands/infos').filter(file => file.endsWith('.js')); -const music = fs.readdirSync('./commands/music').filter(file => file.endsWith('.js')); +fs.readdirSync('./commands').forEach(dirs => { + const commands = fs.readdirSync(`./commands/${dirs}`).filter(files => files.endsWith('.js')); -for (const file of core) { - console.log(`Loading command ${file}`); - const command = require(`./commands/core/${file}`); - client.commands.set(command.name.toLowerCase(), command); -}; - -for (const file of infos) { - console.log(`Loading command ${file}`); - const command = require(`./commands/infos/${file}`); - client.commands.set(command.name.toLowerCase(), command); -}; - -for (const file of music) { - console.log(`Loading command ${file}`); - const command = require(`./commands/music/${file}`); - client.commands.set(command.name.toLowerCase(), command); -}; + for (const file of commands) { + const command = require(`./commands/${dirs}/${file}`); + console.log(`Loading command ${file}`); + client.commands.set(command.name.toLowerCase(), command); + }; +}); const events = fs.readdirSync('./events').filter(file => file.endsWith('.js')); const player = fs.readdirSync('./player').filter(file => file.endsWith('.js')); @@ -48,4 +36,4 @@ for (const file of player) { client.player.on(file.split(".")[0], event.bind(null, client)); }; -client.login(client.config.token_bot); \ No newline at end of file +client.login(client.config.discord.token); \ No newline at end of file diff --git a/package.json b/package.json index 6ae45ae..956e941 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,14 @@ { "name": "music-bot", - "version": "3.0.0", "main": "index.js", - "repository": "https://github.com/ZerioDev/Music-bot.git", "author": "ZerioDev", - "license": "MIT", + "version": "4.0.0", + "repository": "https://github.com/ZerioDev/Music-bot.git", + "description": "A complete code to download for a music bot. Using a module (discord-player).", "dependencies": { - "@discordjs/opus": "^0.3.2", - "discord-player": "^3.0.2", - "discord.js": "^12.2.0", + "@discordjs/opus": "^0.3.3", + "discord-player": "^3.0.3", + "discord.js": "^12.5.1", "ffmpeg-static": "^4.2.7" } } \ No newline at end of file