Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
HazelMoon committed Jul 6, 2021
0 parents commit bbe381a
Show file tree
Hide file tree
Showing 37 changed files with 2,698 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Node
node_modules/
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Music-bot
A complete code to download for a music bot. Using a module (discord-player) 🎧

Looking for a code for a music bot ? This fully open source code is made for your project !

If you need help with this project, to get support faster you can join the help server by just clicking [here](https://discord.gg/5cGSYV8ZZj).

### ⚡ Installation

Well, let's start by downloading the code.
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
emojis: {
off: ':x:',
error: ':warning:',
queue: ':bar_chart:',
music: ':musical_note:',
success: ':white_check_mark:',
}
```

- For configuration

```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.
- `activity`, the activity of the bot.

In the console, type `npm install` to install all dependencies.

- To start the bot :

```
#With Node
node index.js
npm start #Indicated in package.json
#With pm2
pm2 start index.js --name "MusicBot"
```

All you have to do is turn on your bot !

### 🎵 Music commands

```
play <name/URL>, play music in a voice channel.
search <name>, open a panel to choose a music and then play it.
pause, pause the current music.
resume, puts the current music back on.
queue, see the next songs.
clear-queue, remove music in the queue.
shuffle, to mix the queue.
nowplaying, see music in progress.
loop, to enable or disable the repeat function.
volume <1 - 100>, change the volume.
skip, skip to next music.
stop, stop all music.
filter <filter>, add / remove filter.
w-filters, see filters.
```

### 💡 General commands

```
ping, see the bot latency.
help, see the list of available commands.
debug, see number of voice connections.
```

### 🏓 Utilities (to change the code)

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).
48 changes: 48 additions & 0 deletions commands/core/help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module.exports = {
name: 'help',
aliases: ['h'],
category: 'Core',
utilisation: '{prefix}help <command name>',

execute(client, message, args) {
if (!args[0]) {
const infos = message.client.commands.filter(x => x.category == 'Infos').map((x) => '`' + x.name + '`').join(', ');
const music = message.client.commands.filter(x => x.category == 'Music').map((x) => '`' + x.name + '`').join(', ');

message.channel.send({
embed: {
color: 'ORANGE',
author: { name: 'Help pannel' },
footer: { text: 'This bot uses a Github project made by Zerio (ZerioDev/Music-bot)' },
fields: [
{ name: 'Bot', value: infos },
{ name: 'Music', value: music },
{ name: 'Filters', value: client.filters.map((x) => '`' + x + '`').join(', ') },
],
timestamp: new Date(),
description: `To use filters, ${client.config.discord.prefix}filter (the filter). Example : ${client.config.discord.prefix}filter 8D.`,
},
});
} else {
const command = message.client.commands.get(args.join(" ").toLowerCase()) || message.client.commands.find(x => x.aliases && x.aliases.includes(args.join(" ").toLowerCase()));

if (!command) return message.channel.send(`${client.emotes.error} - I did not find this command !`);

message.channel.send({
embed: {
color: 'ORANGE',
author: { name: 'Help pannel' },
footer: { text: 'This bot uses a Github project made by Zerio (ZerioDev/Music-bot)' },
fields: [
{ 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(', '), 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 `<>`.',
}
});
};
},
};
10 changes: 10 additions & 0 deletions commands/infos/debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
name: 'debug',
aliases: [],
category: 'Infos',
utilisation: '{prefix}debug',

execute(client, message) {
message.channel.send(`${client.emotes.success} - ${client.user.username} connected in **${client.voice.connections.size}** channels !`);
},
};
10 changes: 10 additions & 0 deletions commands/infos/ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
name: 'ping',
aliases: [],
category: 'Infos',
utilisation: '{prefix}ping',

execute(client, message) {
message.channel.send(`${client.emotes.success} - Ping : **${client.ws.ping}ms** !`);
},
};
20 changes: 20 additions & 0 deletions commands/music/clear-queue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
name: 'clear-queue',
aliases: ['cq'],
category: 'Music',
utilisation: '{prefix}clear-queue',

execute(client, message) {
if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`);

if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`);

if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`);

if (client.player.getQueue(message).tracks.length <= 1) return message.channel.send(`${client.emotes.error} - There is only one song in the queue.`);

client.player.clearQueue(message);

message.channel.send(`${client.emotes.success} - The queue has just been **removed** !`);
},
};
29 changes: 29 additions & 0 deletions commands/music/filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
name: 'filter',
aliases: [],
category: 'Music',
utilisation: '{prefix}filter [filter name]',

execute(client, message, args) {
if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`);

if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`);

if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`);

if (!args[0]) return message.channel.send(`${client.emotes.error} - Please specify a valid filter to enable or disable !`);

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, try for example (8D, vibrato, pulsator...) !`);

const filtersUpdated = {};

filtersUpdated[filterToUpdate] = client.player.getQueue(message).filters[filterToUpdate] ? false : true;

client.player.setFilters(message, filtersUpdated);

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.`);
},
};
32 changes: 32 additions & 0 deletions commands/music/loop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = {
name: 'loop',
aliases: ['lp', 'repeat'],
category: 'Music',
utilisation: '{prefix}loop',

execute(client, message, args) {
if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`);

if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`);

if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`);

if (args.join(" ").toLowerCase() === 'queue') {
if (client.player.getQueue(message).loopMode) {
client.player.setLoopMode(message, false);
return message.channel.send(`${client.emotes.success} - Repeat mode **disabled** !`);
} else {
client.player.setLoopMode(message, true);
return message.channel.send(`${client.emotes.success} - Repeat mode **enabled** the whole queue will be repeated endlessly !`);
};
} else {
if (client.player.getQueue(message).repeatMode) {
client.player.setRepeatMode(message, false);
return message.channel.send(`${client.emotes.success} - Repeat mode **disabled** !`);
} else {
client.player.setRepeatMode(message, true);
return message.channel.send(`${client.emotes.success} - Repeat mode **enabled** the current music will be repeated endlessly !`);
};
};
},
};
44 changes: 44 additions & 0 deletions commands/music/nowplaying.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module.exports = {
name: 'nowplaying',
aliases: ['np'],
category: 'Music',
utilisation: '{prefix}nowplaying',

execute(client, message) {
if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`);

if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`);

if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`);

const track = client.player.nowPlaying(message);
const filters = [];

Object.keys(client.player.getQueue(message).filters).forEach((filterName) => client.player.getQueue(message).filters[filterName]) ? filters.push(filterName) : false;

message.channel.send({
embed: {
color: 'RED',
author: { name: track.title },
footer: { text: 'This bot uses a Github project made by Zerio (ZerioDev/Music-bot)' },
fields: [
{ name: 'Channel', value: track.author, inline: true },
{ name: 'Requested by', value: track.requestedBy.username, inline: true },
{ name: 'From playlist', value: track.fromPlaylist ? 'Yes' : 'No', inline: true },

{ name: 'Views', value: track.views, inline: true },
{ name: 'Duration', value: track.duration, 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 },
{ name: 'Currently paused', value: client.player.getQueue(message).paused ? 'Yes' : 'No', inline: true },

{ name: 'Progress bar', value: client.player.createProgressBar(message, { timecodes: true }), inline: true }
],
thumbnail: { url: track.thumbnail },
timestamp: new Date(),
},
});
},
};
20 changes: 20 additions & 0 deletions commands/music/pause.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
name: 'pause',
aliases: [],
category: 'Music',
utilisation: '{prefix}pause',

execute(client, message) {
if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`);

if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`);

if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`);

if (client.player.getQueue(message).paused) return message.channel.send(`${client.emotes.error} - The music is already paused !`);

const success = client.player.pause(message);

if (success) message.channel.send(`${client.emotes.success} - Song ${client.player.getQueue(message).playing.title} paused !`);
},
};
16 changes: 16 additions & 0 deletions commands/music/play.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
name: 'play',
aliases: ['p'],
category: 'Music',
utilisation: '{prefix}play [name/URL]',

execute(client, message, args) {
if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`);

if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`);

if (!args[0]) return message.channel.send(`${client.emotes.error} - Please indicate the title of a song !`);

client.player.play(message, args.join(" "), { firstResult: true });
},
};
20 changes: 20 additions & 0 deletions commands/music/queue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
name: 'queue',
aliases: [],
category: 'Music',
utilisation: '{prefix}queue',

execute(client, message) {
if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`);

if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`);

const queue = client.player.getQueue(message);

if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No songs currently playing !`);

message.channel.send(`**Server queue - ${message.guild.name} ${client.emotes.queue} ${client.player.getQueue(message).loopMode ? '(looped)' : ''}**\nCurrent : ${queue.playing.title} | ${queue.playing.author}\n\n` + (queue.tracks.map((track, i) => {
return `**#${i + 1}** - ${track.title} | ${track.author} (requested by : ${track.requestedBy.username})`
}).slice(0, 5).join('\n') + `\n\n${queue.tracks.length > 5 ? `And **${queue.tracks.length - 5}** other songs...` : `In the playlist **${queue.tracks.length}** song(s)...`}`));
},
};
20 changes: 20 additions & 0 deletions commands/music/resume.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
name: 'resume',
aliases: [],
category: 'Music',
utilisation: '{prefix}resume',

execute(client, message) {
if (!message.member.voice.channel) return message.channel.send(`${client.emotes.error} - You're not in a voice channel !`);

if (message.guild.me.voice.channel && message.member.voice.channel.id !== message.guild.me.voice.channel.id) return message.channel.send(`${client.emotes.error} - You are not in the same voice channel !`);

if (!client.player.getQueue(message)) return message.channel.send(`${client.emotes.error} - No music currently playing !`);

if (!client.player.getQueue(message).paused) return message.channel.send(`${client.emotes.error} - The music is already playing !`);

const success = client.player.resume(message);

if (success) message.channel.send(`${client.emotes.success} - Song ${client.player.getQueue(message).playing.title} resumed !`);
},
};
Loading

0 comments on commit bbe381a

Please sign in to comment.