Skip to content

Commit 6ca173d

Browse files
committed
Updates/Error handling/Readme start
Added some more error handing to the bot and trying to solve the issue of it dropping the music randomly. For now a skip command should clear it out so the bot will work again after. This is also the start of the read me file.
1 parent 5fad0ba commit 6ca173d

File tree

6 files changed

+2658
-6
lines changed

6 files changed

+2658
-6
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
config.json
33

44
commands/reference/
5+
6+
node_modules/

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,23 @@
11
# DiscordMusicBotNode
2-
Attempt at making a discord music bot using node js
2+
This is a new project undertaken by myself and Bianca, it is in the very early development stage.
3+
If you come across some issues feel free to post them in the issues.
4+
5+
### General Setup
6+
To be written.
7+
8+
## COMMAND DOCUMENTATION:
9+
### NOTE:
10+
Anything after ! is a command name and the prefix ! is needed to run the command,
11+
the items in <> are the function arguments and anything with OPTIONAL is as it sounds.
12+
```
13+
!play <SONG-NAME>
14+
```
15+
If the person using the command is in a voice channel and the bot has access to that channel it will connect and play the song listed. This is also the command to continue adding songs to the queue, it covers both functions. The bot will auto disconnect
16+
when the end of the queue is reached.
17+
18+
```
19+
!skip <OPTIONAL amount>
20+
```
21+
If the bot is playing a song it will skip to the next song as long as the person is in the same
22+
voice channel as the bot. If there are no songs after the bot will automatically disconnect.
23+
The argument can be used to say how many songs to skip. (>=1)

commands/ytdltie.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ module.exports = class ytdltie {
7070
const song_queue = this.queue.get(message.guild.id);
7171
if(!song_queue) return message.channel.send("Nothing playing!"); // Check for empty queue first.
7272
if(song_queue.voice_channel != voiceChannel || !voiceChannel) return message.channel.send("Please join the same voice channel as me.");
73+
if(amount <= 0) return message.channel.send("Please enter a valid skip amount. (>=1)");
7374
amount--;
7475
while(amount > 0){
7576
song_queue.songs.shift();
@@ -80,7 +81,7 @@ module.exports = class ytdltie {
8081
}
8182
catch(err) { // Clear the buffer if we have trouble ending the queue.
8283
song_queue.voice_channel.leave();
83-
this.queue.delete(guild.id);
84+
this.queue.delete(message.guild.id);
8485
return;
8586
}
8687
}
@@ -116,7 +117,7 @@ module.exports = class ytdltie {
116117
const embed = new this.Discord.MessageEmbed();
117118
embed.setTitle("Queue");
118119
embed.setDescription(pages[pageSafe - 1]);
119-
embed.setFooter("Page: " + page + "/" + pages.length);
120+
embed.setFooter("Page: " + pageSafe + "/" + pages.length);
120121
message.channel.send(embed);
121122

122123
}

index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ ffmpeg-static
66
yt-search
77
ytdl-core
88
9+
Ubuntu node install:
10+
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
11+
sudo apt-get install -y nodejs
912
*/
1013
const ytdltie = require('./commands/ytdltie.js');
1114
const Discord = require('discord.js');
@@ -25,6 +28,10 @@ client.on('message', async message => { // Main event handler for all messages.
2528
if(message.author.bot || !message.content.startsWith(prefix)) return;
2629
const args = message.content.slice(prefix.length).split(/ +/);
2730
const command = args.shift().toLowerCase();
31+
commandHandler(command,args,message)
32+
});
33+
34+
async function commandHandler(command,args,message){
2835
try {
2936
if(command == 'queue'){
3037
if(args.length > 0)
@@ -41,13 +48,13 @@ client.on('message', async message => { // Main event handler for all messages.
4148
await MusicHandler.play(message,song)
4249
}else if(command == 'skip') {
4350
if(args.length > 0)
44-
MusicHandler.skip(message, args[0])
51+
MusicHandler.skip(message, args[0]) // Given skip amount
4552
else
46-
MusicHandler.skip(message)
53+
MusicHandler.skip(message) // Default to 1
4754
} else if(command == 'shuffle'){
4855
MusicHandler.shuffle(message);
4956
}
5057
} catch(err) {
5158
console.log(err);
5259
}
53-
});
60+
}

0 commit comments

Comments
 (0)