Skip to content

Commit

Permalink
fixed issue with the stop command, updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Vauetrr committed Dec 2, 2021
1 parent 6398d6c commit 8b78b96
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# discord-music-bot
A small project to make a discord music bot for a private discord server.

The program uses the discord, os, and youtube_dl libraries, and has dependencies on the pynacl library and ffmpeg.
The program uses the discord, os, and youtube_dl libraries, and has dependencies on the asyncio library, pynacl library and ffmpeg.

# commands
The bot's commands use the prefix "bt ". The current commands are:

* play [youtube url] - Apply the join command, then play the audio of the youtube url
* play [youtube url] - Apply the join command, then play the audio of the youtube url, or add the track to the playlist (if audio already playing)
* join - Joins the voice channel of the user who invoked the command, otherwise joins the first voice channel it finds (if any)
* leave - Leaves the currently joined voice channel (if in a voice channel)
* pause - Pauses the music being played
* resume - Resumes music that has been paused
* stop - Stops the currently playing/paused music
* skip - Skips the current track and plays the next one in the playlist (if any)
* insert [youtube url] - Insert the youtube track at the top of the playlist
* shuffle - Shuffle the order of the tracks in the playlist
10 changes: 9 additions & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
@client.event
async def on_ready():
print(f'{client.user} logged in')
# disconnect from voice channels bot may have been left in
for voice in client.voice_clients:
await voice.connect()
await voice.disconnect(force=True)

@client.event
async def on_disconnect():
Expand Down Expand Up @@ -144,7 +148,11 @@ async def skip(ctx):
"""stops playing the current track and plays the next in the queue (if any)"""
voice = discord.utils.get(client.voice_clients, guild=ctx.guild)
if voice is not None and (voice.is_playing() or voice.is_paused()):
await voice.stop()
# this is in a try/except because the voice doesn't stop fast enough without await
try:
await voice.stop()
except TypeError:
pass
if len(playlist):
newCtx, url = playlist.pop(0)
await play(newCtx, url)
Expand Down

0 comments on commit 8b78b96

Please sign in to comment.