Bug fixes & update (v4.0.0)

This commit is contained in:
Zerio
2020-12-21 23:52:02 +01:00
parent db26c1faa6
commit 109e1051e5
17 changed files with 77 additions and 114 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,2 @@
# Node
node_modules/

View File

@@ -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

View File

@@ -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 `<>`.',

View File

@@ -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 !`);
},
};

View File

@@ -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.`);
},
};

View File

@@ -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 },

View File

@@ -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 !`);
},
};

View File

@@ -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 !`);
},
};

View File

@@ -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.`,
},
});
},

17
config/bot.js Normal file
View File

@@ -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'],
};

View File

@@ -1,5 +0,0 @@
{
"game": "GAME",
"prefix": "PREFIX",
"token_bot": "TOKEN"
}

View File

@@ -1,6 +0,0 @@
{
"music": ":musical_note:",
"queue": ":bar_chart:",
"error": ":x:",
"success": ":white_check_mark:"
}

View File

@@ -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"
}

View File

@@ -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);
};

View File

@@ -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);
};

View File

@@ -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) {
for (const file of commands) {
const command = require(`./commands/${dirs}/${file}`);
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);
};
};
});
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);
client.login(client.config.discord.token);

View File

@@ -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"
}
}