diff --git a/README.md b/README.md index eb5214b..1ad6f9e 100644 --- a/README.md +++ b/README.md @@ -10,18 +10,19 @@ For the bot to be able to start, please complete the file with your credentials ```js { - "prefix": "PREFIX BOT", + "prefix": "PREFIX", + + "game": "GAME", - "token_bot": "TOKEN BOT", - "youtube_api": "TOKEN YOUTUBE API" + "token_bot": "TOKEN" } ``` Reminder : - `prefix`, the prefix that will be set to use the bot. +- `game`, the status of the bot. - `token_bot`, the token of the bot available on the [Discord Developers](https://discordapp.com/developers/applications) section. -- `youtube_api`, your youtube token available on the [Google console](https://console.developers.google.com). To customize the emojis go to the file `emojis.json`. Emojis are already defined by default but you can modify them if you wish. @@ -30,7 +31,7 @@ Emojis are already defined by default but you can modify them if you wish. { "music": ":musical_note:", "queue": ":bar_chart:", - "error": ":tools:", + "error": ":x:", "success": ":white_check_mark:" } ``` @@ -38,61 +39,47 @@ Emojis are already defined by default but you can modify them if you wish. Go to the console and type this : ``` -npm init -npm i (name of each missing module) +npm i +``` + +To start the bot : + +``` +#With Node +node index.js + +#With pm2 +pm2 start index.js --name "MusicBot" ``` All you have to do is turn on your bot ! -- `play `, play music in a vocal salon. -- `pause`, pauses the current music. -- `resume`, puts the current music back on. -- `queue`, see the next musics. -- `clear-queue`, delete the next music. -- `now-playing`, see music in progress. -- `set-volume <...>`, change the volume. -- `set-repeat`to enable or disable the repeat function. -- `skip`, skip to next music. -- `stop`, stop all music. +### 🎵 Music commands +``` +play , play music in a vocal salon. +pause, pause the current music. +resume, puts the current music back on. +queue, see the next musics. +np, see music in progress. +volume <1 - 100>, change the volume. +loop, to enable or disable the repeat function. +skip, skip to next music. +stop, stop all music. +filter , add / remove filters. +w-filters, see filters. +clear-queue, delete the next music. +``` + +### 💡 General commands + +``` +help, see the list of available orders. +ping, see the bot latency. +``` Utilities (to change the code) : -Functions available with the `discord-player` module that you can use : - -```js -// Play a song in the voice channel and init the guild queue -client.player.play(voiceChannel, songName); - -// Add a song to the queue -client.player.addToQueue(guildID, songName); -// Clear the queue -client.player.clearQueue(guildID); -// Get the queue -client.player.getQueue(guildID); -// Skip the current song -client.player.skip(guildID); - - -// Pause -client.player.pause(guildID); -// Resume -client.player.resume(guildID); -// Stop -client.player.stop(guildID); - -// Check if music is playing in a guild -client.player.isPlaying(guildID); -// Get the currently playing song -client.player.nowPlaying(guildID); - - -// Current song will be repeated indefinitely -client.player.setRepeatMode(true); -// Current song will no longer be repeated indefinitely -client.player.setRepeatMode(false); -``` - 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). diff --git a/commands/clear-queue.js b/commands/clear-queue.js index 6eb9e4b..7f100ce 100644 --- a/commands/clear-queue.js +++ b/commands/clear-queue.js @@ -1,18 +1,18 @@ const emotes = require ("../config/emojis.json"); +const Discord = require("discord.js") -module.exports.run = async (client, message) => { +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 the member is not in a voice channel + 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 there's no music + if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`No music playing on this server ${emotes.error}`); + //The bot removes the waiting list client.player.clearQueue(message.guild.id); - message.channel.send(`**Queue cleared ${emotes.success}**`); + //Success message + message.channel.send(`Queue cleared ${emotes.success}`); -}; - -module.exports.config = { - name: "clear-queue", - aliases: [] -}; +} diff --git a/commands/filter.js b/commands/filter.js new file mode 100644 index 0000000..42e7143 --- /dev/null +++ b/commands/filter.js @@ -0,0 +1,41 @@ +const emotes = require ("../config/emojis.json"); +const filters = require("../config/filters.json"); +const Discord = require("discord.js") + +exports.run = async (client, message, args) => { + + //If the member is not in a voice channel + if(!message.member.voice.channel) return message.channel.send(`You're not in a voice channel ${emotes.error}`); + + //If there's no music + if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`No music playing on this server ${emotes.error}`); + + //Filter + const filter = args[0]; + if(!filter) return message.channel.send(`Please specify a valid filter to enable or disable ${emotes.error}`); + + const filterToUpdate = Object.values(filters).find((f) => f.toLowerCase() === filter.toLowerCase()); + + //If he can't find the filter + if(!filterToUpdate) return message.channel.send(`This filter doesn't exist ${emotes.error}`); + + const filterRealName = Object.keys(filters).find((f) => filters[f] === filterToUpdate); + + const queueFilters = client.player.getQueue(message.guild.id).filters + const filtersUpdated = {}; + filtersUpdated[filterRealName] = queueFilters[filterRealName] ? false : true; + client.player.setFilters(message.guild.id, filtersUpdated); + + if(filtersUpdated[filterRealName]) { + + //The bot adds the filter on the music + message.channel.send(`I'm adding the filter to the music, please wait... Note : the longer the music is, the longer the wait will be ${emotes.music}`); + + } else { + + //The bot removes the filter from the music + message.channel.send(`I'm disabling the filter on the music, please wait... Note : the longer the music is playing, the longer the wait will be ${emotes.music}`); + + } + +} diff --git a/commands/help.js b/commands/help.js new file mode 100644 index 0000000..552c2b7 --- /dev/null +++ b/commands/help.js @@ -0,0 +1,19 @@ +const config = require ("../config/bot.json"); +const emotes = require ("../config/emojis.json"); +const Discord = require("discord.js") + +exports.run = async (client, message, args) => { + + //New embed + const help = new Discord.MessageEmbed() + .setDescription("Find the list of commands available on this panel.") + .addField("**Music**", "`play`, `pause`, `resume`, `queue`, `clear-queue`, `shuffle`, `np`, `loop`, `volume`, `skip`, `stop`") + .addField("**Filters**", "`bassboost`, `tremolo`, `vibrato`, `treble`, `8D`, `normalizer`, `surrounding`, `nightcore`, `vaporwave`, `superequalizer`, `phaser`, `reverse`, `pulsator`") + .addField("**Informations**", "`ping`") + .setFooter(`To use filters, ${config.prefix}filter (the filter). Example : ${config.prefix}filter 8D.`) + .setColor("ORANGE") + + //Message + message.channel.send(help) + +} diff --git a/commands/loop.js b/commands/loop.js new file mode 100644 index 0000000..2336c44 --- /dev/null +++ b/commands/loop.js @@ -0,0 +1,33 @@ +const emotes = require ("../config/emojis.json"); +const Discord = require("discord.js") + +exports.run = async (client, message, args) => { + + //If the member is not in a voice channel + if(!message.member.voice.channel) return message.channel.send(`You're not in a voice channel ${emotes.error}`); + + //If there's no music + if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`No music playing on this server ${emotes.error}`); + + //Repeat mode + const repeatMode = client.player.getQueue(message.guild.id).repeatMode; + + //If the mode is enabled + if(repeatMode) { + + client.player.setRepeatMode(message.guild.id, false); + + //Message + return message.channel.send(`Repeat mode disabled ${emotes.success}`); + + //If the mode is disabled + } else { + + client.player.setRepeatMode(message.guild.id, true); + + //Message + return message.channel.send(`Repeat mode enabled ${emotes.success}`); + + } + +} diff --git a/commands/now-playing.js b/commands/now-playing.js deleted file mode 100644 index f7e3f81..0000000 --- a/commands/now-playing.js +++ /dev/null @@ -1,18 +0,0 @@ -const emotes = require ("../config/emojis.json"); - -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(!client.player.isPlaying(message.guild.id)) return message.channel.send(`**No music playing on this server ${emotes.error}**`); - - const song = await client.player.nowPlaying(message.guild.id); - - message.channel.send(`**Currently playing ${song.name} ${emotes.music}**`); - -}; - -module.exports.config = { - name: "now-playing", - aliases: [] -}; diff --git a/commands/np.js b/commands/np.js new file mode 100644 index 0000000..46faf2f --- /dev/null +++ b/commands/np.js @@ -0,0 +1,17 @@ +const emotes = require ("../config/emojis.json"); +const Discord = require("discord.js") + +exports.run = async (client, message, args) => { + + //If the member is not in a voice channel + if(!message.member.voice.channel) return message.channel.send(`You're not in a voice channel ${emotes.error}`); + + //If there's no music + if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`No music playing on this server ${emotes.error}`); + + const song = await client.player.nowPlaying(message.guild.id); + + //Message + message.channel.send(`Currently playing ${song.name} ${emotes.music}\nProgression : [${client.player.createProgressBar(message.guild.id)}]`); + +} diff --git a/commands/pause.js b/commands/pause.js index c47c072..eeac198 100644 --- a/commands/pause.js +++ b/commands/pause.js @@ -1,20 +1,17 @@ +const emotes = require ("../config/emojis.json"); const Discord = require("discord.js") -const fs = require("fs") -const emotes = require ("../config/emojis.json") -module.exports.run = async (client, message) => { +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 the member is not in a voice channel + 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 there's no music + 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); + const track = await client.player.pause(message.guild.id); - message.channel.send(`**Song ${song.name} paused ${emotes.success}**`); + //Message + message.channel.send(`Song ${track.name} paused ${emotes.success}`); -}; - -module.exports.config = { - name: "pause", - aliases: [] -} \ No newline at end of file +} diff --git a/commands/ping.js b/commands/ping.js new file mode 100644 index 0000000..461174d --- /dev/null +++ b/commands/ping.js @@ -0,0 +1,9 @@ +const emotes = require ("../config/emojis.json"); +const Discord = require("discord.js") + +exports.run = async (client, message, args) => { + + //Message + message.channel.send(`Ping : ${client.ws.ping} ms ${emotes.success}`) + +} diff --git a/commands/play.js b/commands/play.js index 59431d2..a84bd9c 100644 --- a/commands/play.js +++ b/commands/play.js @@ -1,27 +1,52 @@ const emotes = require ("../config/emojis.json"); +const Discord = require("discord.js") -module.exports.run = async (client, message, args) => { +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 the member is not in a voice channel + 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}**`); - - const aSongIsAlreadyPlaying = client.player.isPlaying(message.guild.id); + //If no music is provided + if (!args[0]) return message.channel.send(`Please enter a music ${emotes.error}`); - // If there's already a song playing - if(aSongIsAlreadyPlaying){ - // Add the song to the queue - const song = await client.player.addToQueue(message.guild.id, args.join(" ")); - message.channel.send(`**Song ${song.name} added to queue ${emotes.music}**`); - } else { - // Else, play the song - const song = await client.player.play(message.member.voice.channel, args.join(" ")); - message.channel.send(`**Currently playing ${song.name} ${emotes.music}**`); + const aTrackIsAlreadyPlaying = client.player.isPlaying(message.guild.id); + + // If there's already a track playing + if(aTrackIsAlreadyPlaying){ + + // Add the track to the queue + const result = await client.player.addToQueue(message.guild.id, args[0]); + if(!result) return message.channel.send(`This song provider is not supported...`); + + if(result.type === 'playlist'){ + message.channel.send(`${result.tracks.length} songs added to the queue ${emotes.music}`); + } else { + message.channel.send(`${result.name} added to the queue ${emotes.music}`); + } + + } else { + + // Else, play the song + const result = await client.player.play(message.member.voice.channel, args.join(" ")).catch(() => {}); + if(!result) return message.channel.send(`This song provider is not supported...`); + + if(result.type === 'playlist'){ + message.channel.send(`${result.tracks.length} songs added to the queue ${emotes.music}\nCurrently playing ${result.tracks[0].name} !`); + } else { + message.channel.send(`Currently playing ${result.name} ${emotes.music}`); + } + + const queue = client.player.getQueue(message.guild.id) + + //Events + .on('end', () => { + message.channel.send(`There is no more music in the queue ${emotes.error}`); + }) + .on('trackChanged', (oldTrack, newTrack) => { + message.channel.send(`Now playing ${newTrack.name} ... ${emotes.music}`); + }) + .on('channelEmpty', () => { + message.channel.send(`Stop playing, there is no more member in the voice channel ${emotes.error}`); + }); + } } -}; - - -module.exports.config = { - name: "play", - aliases: [] -}; \ No newline at end of file diff --git a/commands/queue.js b/commands/queue.js index 36d1309..533a9fb 100644 --- a/commands/queue.js +++ b/commands/queue.js @@ -1,21 +1,23 @@ const emotes = require ("../config/emojis.json"); +const Discord = require("discord.js") -module.exports.run = async (client, message) => { +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 the member is not in a voice channel + if(!message.member.voice.channel) return message.channel.send(`You're not in a voice channel ${emotes.error}`); + //Get queue const queue = client.player.getQueue(message.guild.id); - if(!queue) return message.channel.send(`**No songs currently playing ${emotes.error}**`); + //If there's no music + if(!queue) return message.channel.send(`No songs currently playing ${emotes.error}`); - message.channel.send(`**Server queue ${emotes.queue}** \n`+(queue.songs.map((song, i) => { - return `${i === 0 ? 'Current' : `#${i+1}`} - ${song.name} | ${song.author}` - }).join('\n'))); + //Message + message.channel.send(`**Server queue ${emotes.queue}**\nCurrent - ${queue.playing.name} | ${queue.playing.author}\n`+ + ( + queue.tracks.map((track, i) => { + return `#${i+1} - ${track.name} | ${track.author}` + }).join('\n') + )); -}; - - -module.exports.config = { - name: "queue", - aliases: [] -}; +} diff --git a/commands/resume.js b/commands/resume.js index 0564d29..02c69bc 100644 --- a/commands/resume.js +++ b/commands/resume.js @@ -1,18 +1,18 @@ const emotes = require ("../config/emojis.json"); +const Discord = require("discord.js") -module.exports.run = async (client, message) => { +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 the member is not in a voice channel + if(!message.member.voice.channel) return message.channel.send(`You're not in a voice channel ${emotes.error}`); + //Get song const song = await client.player.resume(message.guild.id); - if(!song) return message.channel.send(`**No songs currently playing ${emotes.error}**`); + //If there's no music + if(!song) return message.channel.send(`No songs currently playing ${emotes.error}`); - message.channel.send(`**Song ${song.name} resumed ${emotes.success}**`); + //Message + message.channel.send(`Song ${song.name} resumed ${emotes.success}`); -}; - -module.exports.config = { - name: "resume", - aliases: [] -}; \ No newline at end of file +} diff --git a/commands/set-repeat.js b/commands/set-repeat.js deleted file mode 100644 index bb095dc..0000000 --- a/commands/set-repeat.js +++ /dev/null @@ -1,24 +0,0 @@ -const emotes = require ("../config/emojis.json"); - -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(!client.player.isPlaying(message.guild.id)) return message.channel.send(`**No music playing on this server ${emotes.error}**`); - - const repeatMode = client.player.getQueue(message.guild.id).repeatMode; - - if(repeatMode){ - client.player.setRepeatMode(message.guild.id, false); - return message.channel.send(`**Repeat mode disabled ${emotes.success}**`); - } else { - client.player.setRepeatMode(message.guild.id, true); - return message.channel.send(`**Repeat mode enabled ${emotes.success}**`); - } - -}; - -module.exports.config = { - name: "set-repeat", - aliases: [] -}; diff --git a/commands/set-volume.js b/commands/set-volume.js deleted file mode 100644 index e257d55..0000000 --- a/commands/set-volume.js +++ /dev/null @@ -1,21 +0,0 @@ -const emotes = require ("../config/emojis.json"); - -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(!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(" "))); - - message.channel.send("**Volume set to** `" + args.join(" ") + "`" + `** ** ${emotes.success}`); - - -}; - -module.exports.config = { - name: "set-volume", - aliases: [] -}; diff --git a/commands/shuffle.js b/commands/shuffle.js index 0040a2b..7b18769 100644 --- a/commands/shuffle.js +++ b/commands/shuffle.js @@ -1,17 +1,17 @@ const emotes = require ("../config/emojis.json"); +const Discord = require("discord.js") -module.exports.run = async (client, message) => { +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 the member is not in a voice channel + 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 there's no music + if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`No music playing on this server ${emotes.error}`); client.player.shuffle(message.guild.id); - return message.channel.send(`**Queue shuffled ${emotes.success}**`); - -}; -module.exports.config = { - name: "shuffle", - aliases: [] -}; + //Message + return message.channel.send(`Queue shuffled ${emotes.success}`); + +} diff --git a/commands/skip.js b/commands/skip.js index b1dd767..52cdb84 100644 --- a/commands/skip.js +++ b/commands/skip.js @@ -1,18 +1,17 @@ const emotes = require ("../config/emojis.json"); +const Discord = require("discord.js") -module.exports.run = async (client, message) => { +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 the member is not in a voice channel + 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 there's no music + if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`No music playing on this server ${emotes.error}`); - const song = await client.player.skip(message.guild.id); + const track = await client.player.skip(message.guild.id); - message.channel.send(`**Song ${song.name} skipped ${emotes.success}**`); + //Message + message.channel.send(`Song ${track.name} skipped ${emotes.success}`); -}; - -module.exports.config = { - name: "skip", - aliases: [] -}; +} diff --git a/commands/stop.js b/commands/stop.js index 8474e45..5a7dea0 100644 --- a/commands/stop.js +++ b/commands/stop.js @@ -1,18 +1,18 @@ const emotes = require ("../config/emojis.json"); +const Discord = require("discord.js") -module.exports.run = async (client, message) => { +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 the member is not in a voice channel + 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 there's no music + if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`No music playing on this server ${emotes.error}`); + //Stop player client.player.stop(message.guild.id); - message.channel.send(`**Music stopped ${emotes.success}**`); + //Message + message.channel.send(`Music stopped ${emotes.success}`); -}; - -module.exports.config = { - name: "stop", - aliases: [] -}; +} diff --git a/commands/volume.js b/commands/volume.js new file mode 100644 index 0000000..d497126 --- /dev/null +++ b/commands/volume.js @@ -0,0 +1,32 @@ +const emotes = require ("../config/emojis.json"); +const Discord = require("discord.js") + +exports.run = async (client, message, args) => { + + //If the member is not in a voice channel + if(!message.member.voice.channel) return message.channel.send(`You're not in a voice channel ${emotes.error}`); + + //If there's no music + if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`No music playing on this server ${emotes.error}`); + + //Args + if(!args[0]) return message.channel.send(`Please enter a number ${emotes.error}`); + + //Security modification + if(isNaN(args[0])) return message.channel.send(`Please enter a valid number ${emotes.error}`); + if(100 < args[0]) return message.channel.send(`Please enter a valid number ${emotes.error}`) + if(args[0] <=0) return message.channel.send(`Please enter a valid number ${emotes.error}`) + + //Cannot put (-), (+), (,) or (.) + if(message.content.includes("-")) return message.channel.send(`Please enter a valid number ${emotes.error}`) + if(message.content.includes("+")) return message.channel.send(`Please enter a valid number ${emotes.error}`) + if(message.content.includes(",")) return message.channel.send(`Please enter a valid number ${emotes.error}`) + if(message.content.includes(".")) return message.channel.send(`Please enter a valid number ${emotes.error}`) + + //Set volume + client.player.setVolume(message.guild.id, parseInt(args.join(" "))); + + //Message + message.channel.send(`Volume set to \`${args.join(" ")}\` ${emotes.success}`); + +} diff --git a/commands/w-filters.js b/commands/w-filters.js new file mode 100644 index 0000000..d2b6cd1 --- /dev/null +++ b/commands/w-filters.js @@ -0,0 +1,35 @@ +const config = require ("../config/bot.json"); +const emotes = require ("../config/emojis.json"); +const filters = require ("../config/filters.json"); +const Discord = require("discord.js") + +exports.run = async (client, message, args) => { + + //If the member is not in a voice channel + if(!message.member.voice.channel) return message.channel.send(`You're not in a voice channel ${emotes.error}`); + + //If there's no music + if(!client.player.isPlaying(message.guild.id)) return message.channel.send(`No music playing on this server ${emotes.error}`); + + //Emojis + const enabledEmoji = emotes.success; + const disabledEmoji = emotes.error; + + const filtersStatuses = [ [], [] ]; + + Object.keys(filters).forEach((filterName) => { + const array = filtersStatuses[0].length > filtersStatuses[1].length ? filtersStatuses[1] : filtersStatuses[0]; + array.push(filters[filterName] + " : " + (client.player.getQueue(message.guild.id).filters[filterName] ? enabledEmoji : disabledEmoji)); + }); + + //List embed + const list = new Discord.MessageEmbed() + .setDescription(`List of all filters enabled or disabled.\nTo add a filter to a \`${config.prefix}filter\` music.`) + .addField("**Filters**", filtersStatuses[0].join('\n'), true) + .addField("** **", filtersStatuses[1].join('\n'), true) + .setColor("ORANGE"); + + //Message + message.channel.send(list); + +} diff --git a/config/bot.json b/config/bot.json index 0648d3c..0790469 100644 --- a/config/bot.json +++ b/config/bot.json @@ -1,6 +1,7 @@ { - "prefix": "PREFIX BOT", + "prefix": "PREFIX", + + "game": "GAME", - "token_bot": "TOKEN BOT", - "youtube_api": "TOKEN YOUTUBE API" + "token_bot": "TOKEN" } diff --git a/config/emojis.json b/config/emojis.json index 0077c7d..70efdbd 100644 --- a/config/emojis.json +++ b/config/emojis.json @@ -1,6 +1,6 @@ { "music": ":musical_note:", "queue": ":bar_chart:", - "error": ":tools:", + "error": ":x:", "success": ":white_check_mark:" } diff --git a/config/filters.json b/config/filters.json new file mode 100644 index 0000000..9b847af --- /dev/null +++ b/config/filters.json @@ -0,0 +1,15 @@ +{ + "bassboost": "Bassboost", + "8D": "8D", + "vaporwave": "Vaporwave", + "nightcore": "Nightcore", + "phaser": "Phaser", + "tremolo": "Tremolo", + "vibrato": "Vibrato", + "reverse": "Reverse", + "treble": "Treble", + "normalizer": "Normalizer", + "surrounding": "Surrounding", + "pulsator": "Pulsator", + "superequalizer": "Superequalizer" +} diff --git a/events/message.js b/events/message.js new file mode 100644 index 0000000..0de7eca --- /dev/null +++ b/events/message.js @@ -0,0 +1,27 @@ +const config = require(`../config/bot.json`) + +module.exports = (client, message) => { + + //Ignore all bots + if (message.author.bot) return; + + //Prefix + let prefix = config.prefix + + //Ignore messages not starting with the prefix (in config.json) + if (message.content.indexOf(prefix) !== 0) return; + + //Our standard argument/command name definition. + const args = message.content.slice(prefix.length).trim().split(/ +/g); + const command = args.shift().toLowerCase(); + + //Grab the command data from the client.commands Enmap + const cmd = client.commands.get(command); + + //If that command doesn't exist, silently exit and do nothing + if (!cmd) return; + + //Run the command + cmd.run(client, message, args); + +}; diff --git a/events/ready.js b/events/ready.js new file mode 100644 index 0000000..692338a --- /dev/null +++ b/events/ready.js @@ -0,0 +1,11 @@ +const config = require(`../config/bot.json`) + +module.exports = async (client) => { + + //If the bot is ready it sends a message in the console + console.log(`Ready on ${client.guilds.cache.size} servers, for a total of ${client.users.cache.size} users`); + + //Game + client.user.setActivity(config.game) + +} diff --git a/index.js b/index.js index 050fcf5..1f422ff 100644 --- a/index.js +++ b/index.js @@ -1,59 +1,45 @@ +//Modules const Discord = require("discord.js"); const fs = require("fs"); + +//New 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) - -const player = new Player(client, settings.youtube_api); // To easily access the player +//Create a new Player +const { Player } = require("discord-player") +//To easily access the player +const player = new Player(client) client.player = player; -client.on("ready", () => { - - 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.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(); - -fs.readdir("./commands/", (err, files) => { - - const jsfiles = files.filter(f => f.split(".").pop() === "js") - - if(jsfiles.length <= 0) { - return console.log("Couldn't find any commands!"); - } - - 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); - }); - +//Events +fs.readdir("./events/", (err, files) => { + 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)); }); - }); + +//New commands +client.commands = new Discord.Collection(); + +//Commands +fs.readdir("./commands/", (err, files) => { + if (err) return console.error(err); + files.forEach(file => { + if (!file.endsWith(".js")) return; + let props = require(`./commands/${file}`); + let commandName = file.split(".")[0]; + console.log(`Loading command ${commandName}`); + client.commands.set(commandName, props); + }); +}); + +//Login +client.login(settings.token_bot); diff --git a/package.json b/package.json index 164c62a..37c47fa 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "author": "ZerioDev", "license": "MIT", "dependencies": { - "@discordjs/opus": "^0.1.0", - "discord-player": "^1.4.0", + "@discordjs/opus": "^0.3.2", + "discord-player": "github:Androz2091/discord-player#develop", "discord.js": "^12.2.0" } }