Skip to content

Commit

Permalink
(v1.1) Config & Guide Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatGuyJacobee committed Jun 25, 2023
1 parent 96269ab commit a5de1c7
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 41 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ OWNER_ID=360815761662541824

# GENERAL SETTINGS
EMBED_COLOUR='#FF0000'
PRESENCE='/help | elite-bot.com'

# DJ MODE SETTINGS
ENABLE_DJMODE=false
Expand All @@ -21,4 +22,5 @@ LEAVE_ON_STOP=true
LEAVE_ON_STOP_COOLDOWN=300000

SELF_DEAFEN=true
DEFAULT_VOLUME=50
DEFAULT_VOLUME=50
SMOOTH_VOLUME=true
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Elite Music
Elite Music is a feature-packed Discord Music Bot built on top of discord.js & using the latest discord-player package.
# Elite Music 🎵
Elite Music is a feature-packed Discord Music Bot built on top of [discord.js](https://discord.js.org/) & using the latest [discord-player](https://discord-player.js.org/) package.

## Features
## Features 💡
- Wide range of commands
- Easy to setup and edit
- Easy to setup, customise and edit
- Slash commands (djs v14)
- Support for various streaming platforms
- Wide range of audio filters
Expand All @@ -13,12 +13,12 @@ Elite Music is a feature-packed Discord Music Bot built on top of discord.js & u
Elite Music was originally a part of my verified Discord bot... [Elite Bot](https://elite-bot.com/), but the music section had to be removed due to verification issues. Therefore, in a win situation, I decided to open-source the bot's music code in this repository. And even better, I decided to re-write the entire bot to improve the feature set and overall quality of the code.

# Installation 🔌
## Prerequisites
## Prerequisites 🛂
In order for the bot to function correctly, there are a few prerequisites that you must have on your system.

- [NodeJS](https://nodejs.org/en) - For the bot to function, it must be running in a NodeJS environment running on v17.0 or higher. It is highly recommended that you download the LTS build which is available for your OS to remain on the latest stable version. Head over to the [NodeJS Download website](https://nodejs.org/en/download) to download and install an appropriate version.
- [NodeJS](https://nodejs.org/en) - For the bot to function, it must be running in a NodeJS environment running on v16.9.0 or higher. It is highly recommended that you download the LTS build which is available for your OS to remain on the latest stable version. Head over to the [NodeJS Download website](https://nodejs.org/en/download) to download and install an appropriate version.

- [FFmpeg](https://ffmpeg.org/) or Avconv - You will require either of these for transcoding. It is recommended to use FFmpeg. Head over to the [FFmpeg Download website](https://ffmpeg.org/download.html), select your OS and download the appropriate package. Alternatively, you can use `npm I ffmpeg-static` when setting up the bot to use the binaries, although this is **NOT** recommended.
- [FFmpeg](https://ffmpeg.org/) or Avconv - You will require either of these for transcoding. It is recommended to use FFmpeg. By default, the bot comes with the `ffmpeg-static` binaries as a dependancy which allows the bot to work out of the box. Alternatively, you may decide to set your own ffmpeg binaries. In this case, head over to the [FFmpeg Download website](https://ffmpeg.org/download.html), select your OS and download the appropriate package. You can then place `FFMPEG_PATH` as a new option into your .ENV file stating the custom path to your custom FFmpeg binaries.

- [Discord Bot Account](https://discord.com/developers/applications) - You must register a bot on the Discord Developer site to gain access to a token to run the bot. Head over to the [Developer website](https://discord.com/developers/applications) and click on `New Application` button. Provide a name and press `Create`. Next on the left-hand menu, select the `Bot` section and press `Add Bot` alongside the confirmation. Finally, press `Reset Token` and finally copy the token and keep it safe. This is what you will have to place into your .ENV file for the bot to function.

Expand All @@ -40,17 +40,19 @@ Now that you have downloaded the repository, you can continue with the following
4. Finally, run your bot using `node .` within a command/shell/terminal window. The bot should now become online and provide a success message if everything was configured correctly. 🎉
5. (Optional) If you are editing the code, you can use `npm run dev` within your IDE to activate nodemon, which will automatically restart the bot on any change which is ideal for development.

## Support
Of course, you need to add your bot to your server now in order to use it. Follow this [useful guide](https://discordjs.guide/preparations/adding-your-bot-to-servers.html#bot-invite-links) from the discord.js Guide which explains how to do this with great detail if you need help understanding how to do this.

## Support 🆘
Need help setting up the bot or experiencing some trouble? Feel free to head over to the [Support Discord server](https://discord.elitegami.ng) and let me know!

Found a bug or issue with the latest build? Feel free to open an issue on this repository! I will respond as soon as possible.

## Elite Bot - Verified Multi-Purpose Bot
## Elite Bot - Verified Multi-Purpose Bot 💪
Looking for a multi-purpose Discord Bot for your server? Look no further, check out Elite Bot to fulfil all of your server needs including moderation, logging, external server status and much more!

Check the bot out via the dedicated documentation website or top.gg today! 🚀
- https://elite-bot.com
- https://top.gg/bot/723275350922100840

## License
## License 📄
[Apache © ThatGuyJacobee](./LICENSE.md)
23 changes: 9 additions & 14 deletions commands/music/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { Player, QueryType } = require('discord-player');
module.exports = {
data: new SlashCommandBuilder()
.setName("play")
.setDescription("Plays a song!")
.setDescription("Place a song into the queue!")
.addStringOption((option) => option
.setName("music")
.setDescription("Either the name, URL or playlist URL you want to play.")
Expand All @@ -27,23 +27,18 @@ module.exports = {

if (!checkqueue) {
player.nodes.create(interaction.guild.id, {
leaveOnEmpty: process.env.LEAVE_ON_EMPTY,
leaveOnEmptyCooldown: process.env.LEAVE_ON_EMPTY_COOLDOWN,
leaveOnEnd: process.env.LEAVE_ON_END,
leaveOnEndCooldown: process.env.LEAVE_ON_END_COOLDOWN,
leaveOnStop: process.env.LEAVE_ON_STOP,
leaveOnStopCooldown: process.env.LEAVE_ON_STOP_COOLDOWN,
selfDeaf: process.env.SELF_DEAFEN,
leaveOnEmpty: client.config.leaveOnEmpty,
leaveOnEmptyCooldown: client.config.leaveOnEmptyCooldown,
leaveOnEnd: client.config.leaveOnEnd,
leaveOnEndCooldown: client.config.leaveOnEndCooldown,
leaveOnStop: client.config.leaveOnStop,
leaveOnStopCooldown: client.config.leaveOnStopCooldown,
selfDeaf: client.config.selfDeafen,
skipOnNoStream: true,
metadata: {
channel: interaction.channel,
requestedBy: interaction.user,
client: interaction.guild.members.me,
},
ytdlOptions: {
filter: 'audioonly',
highWaterMark: 1 << 30,
dlChunkSize: 0,
}
})
}
Expand Down Expand Up @@ -80,7 +75,7 @@ module.exports = {
if (!queue.isPlaying()) {
try {
await queue.node.play(queue.tracks[0]);
queue.node.setVolume(process.env.DEFAULT_VOLUME);
queue.node.setVolume(client.config.defaultVolume);
}

catch (err) {
Expand Down
21 changes: 8 additions & 13 deletions commands/music/playnext.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,18 @@ module.exports = {

if (!checkqueue) {
player.nodes.create(interaction.guild.id, {
leaveOnEmpty: process.env.LEAVE_ON_EMPTY,
leaveOnEmptyCooldown: process.env.LEAVE_ON_EMPTY_COOLDOWN,
leaveOnEnd: process.env.LEAVE_ON_END,
leaveOnEndCooldown: process.env.LEAVE_ON_END_COOLDOWN,
leaveOnStop: process.env.LEAVE_ON_STOP,
leaveOnStopCooldown: process.env.LEAVE_ON_STOP_COOLDOWN,
selfDeaf: process.env.SELF_DEAFEN,
leaveOnEmpty: client.config.leaveOnEmpty,
leaveOnEmptyCooldown: client.config.leaveOnEmptyCooldown,
leaveOnEnd: client.config.leaveOnEnd,
leaveOnEndCooldown: client.config.leaveOnEndCooldown,
leaveOnStop: client.config.leaveOnStop,
leaveOnStopCooldown: client.config.leaveOnStopCooldown,
selfDeaf: client.config.selfDeafen,
skipOnNoStream: true,
metadata: {
channel: interaction.channel,
requestedBy: interaction.user,
client: interaction.guild.members.me,
},
ytdlOptions: {
filter: 'audioonly',
highWaterMark: 1 << 30,
dlChunkSize: 0,
}
})
}
Expand Down Expand Up @@ -84,7 +79,7 @@ module.exports = {
if (!queue.isPlaying()) {
try {
await queue.node.play(queue.tracks[0]);
queue.node.setVolume(process.env.DEFAULT_VOLUME);
queue.node.setVolume(client.config.defaultVolume);
}

catch (err) {
Expand Down
67 changes: 65 additions & 2 deletions events/ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,70 @@ module.exports = {
name: "ready",
once: true,
async execute (client, commands){
client.user.setActivity(`/help | elite-bot.com`, { type: 2 });
console.log("[ELITE_STATUS] Checks are successful. Core of the bot is ready!");
client.user.setActivity(process.env.PRESENCE, { type: 2 });

//Configuration checks & initialisation
const defaultConsts = require(`../utils/defaultConsts`);
client.config = defaultConsts.config;

new Promise((resolve, reject) => {
client.config.embedColour = typeof (process.env.EMBED_COLOUR) === 'undefined'
? client.config.embedColour
: ((/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i).test(process.env.EMBED_COLOUR) ? process.env.EMBED_COLOUR : client.config.embedColour);

client.config.presence = typeof (process.env.PRESENCE) === 'undefined'
? client.config.presence
: (String(process.env.PRESENCE) ? process.env.PRESENCE : client.config.presence);

client.config.enableDjMode = typeof (process.env.ENABLE_DJMODE) === 'undefined'
? client.config.enableDjMode
: (String(process.env.ENABLE_DJMODE) === 'true' ? true : false);

client.config.djRole = typeof (process.env.DJ_ROLE) === 'undefined'
? client.config.djRole
: (Number(process.env.DJ_ROLE) ? process.env.DJ_ROLE : client.config.djRole);

client.config.leaveOnEmpty = typeof (process.env.LEAVE_ON_EMPTY) === 'undefined'
? client.config.leaveOnEmpty
: (String(process.env.LEAVE_ON_EMPTY) === 'true' ? true : false);

client.config.leaveOnEmptyCooldown = typeof (process.env.LEAVE_ON_EMPTY_COOLDOWN) === 'undefined'
? client.config.leaveOnEmptyCooldown
: (Number(process.env.LEAVE_ON_EMPTY_COOLDOWN) ? process.env.LEAVE_ON_EMPTY_COOLDOWN : client.config.leaveOnEmptyCooldown);

client.config.leaveOnEnd = typeof (process.env.LEAVE_ON_END) === 'undefined'
? client.config.leaveOnEnd
: (String(process.env.LEAVE_ON_END) === 'true' ? true : false);

client.config.leaveOnEndCooldown = typeof (process.env.LEAVE_ON_END_COOLDOWN) === 'undefined'
? client.config.leaveOnEndCooldown
: (Number(process.env.LEAVE_ON_END_COOLDOWN) ? process.env.LEAVE_ON_END_COOLDOWN : client.config.leaveOnEndCooldown);

client.config.leaveOnStop = typeof (process.env.LEAVE_ON_STOP) === 'undefined'
? client.config.leaveOnStop
: (String(process.env.LEAVE_ON_STOP) === 'true' ? true : false);

client.config.leaveOnStopCooldown = typeof (process.env.LEAVE_ON_STOP_COOLDOWN) === 'undefined'
? client.config.leaveOnStopCooldown
: (Number(process.env.LEAVE_ON_STOP_COOLDOWN) ? process.env.LEAVE_ON_STOP_COOLDOWN : client.config.leaveOnStopCooldown);

client.config.selfDeafen = typeof (process.env.SELF_DEAFEN) === 'undefined'
? client.config.selfDeafen
: (String(process.env.SELF_DEAFEN) === 'true' ? true : false);

client.config.defaultVolume = typeof (process.env.DEFAULT_VOLUME) === 'undefined'
? client.config.defaultVolume
: (Number(process.env.DEFAULT_VOLUME <= 100) && Number(process.env.DEFAULT_VOLUME >= 0) ? process.env.DEFAULT_VOLUME : client.config.defaultVolume);

client.config.smoothVolume = typeof (process.env.SMOOTH_VOLUME) === 'undefined'
? client.config.smoothVolume
: (String(process.env.SMOOTH_VOLUME) === 'true' ? true : false);

console.log(`[ELITE_CONFIG] Configuration loading... Current config:\n${JSON.stringify(client.config, null, 3)}`)
console.log(`Note: If some configuration option is incorrect, please double check that it is correctly set within your .ENV file!\nOtherwise, where a configuraiton option is invalid, the default from defaultConsts.js will be used.`)
resolve();
})

console.log("[ELITE_STATUS] Loading successful. Core of the bot is ready!");
}
}
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ process.on('unhandledRejection', async function(err) {
});

//Discord-Player initialisation
const defaultConsts = require(`./utils/defaultConsts`);
const { YouTubeExtractor, SpotifyExtractor, SoundCloudExtractor, AttachmentExtractor } = require('@discord-player/extractor')
const player = new Player(client, {
smoothVolume: true,
smoothVolume: process.env.SMOOTH_VOLUME,
ytdlOptions: defaultConsts.ytdlOptions
})
player.extractors.register(YouTubeExtractor, SpotifyExtractor, SoundCloudExtractor, AttachmentExtractor)

Expand Down
26 changes: 26 additions & 0 deletions utils/defaultConsts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//Defaul configruations to use for undefined/incorrect values in the .env file.
const defaultConsts = {
config: {
embedColour: '#FF0000',
presence: '/help | elite-bot.com',
enableDjMode: false,
djRole: 1234567891011,
leaveOnEmpty: false,
leaveOnEmptyCooldown: 0,
leaveOnEnd: false,
leaveOnEndCooldown: 0,
leaveOnStop: false,
leaveOnStopCooldown: 0,
selfDeafen: true,
defaultVolume: 50,
smoothVolume: true,
},
ytdlOptions: {
filter: 'audioonly',
quality: 'highestaudio',
highWaterMark: 1 << 30,
dlChunkSize: 0,
}
}

module.exports = defaultConsts;

0 comments on commit a5de1c7

Please sign in to comment.