Skip to content

Commit

Permalink
Added emojis and error handling on connect command
Browse files Browse the repository at this point in the history
  • Loading branch information
shahriyardx committed Feb 8, 2022
1 parent ef16599 commit a1e1dac
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions dismusic/music.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import wavelink
from discord import Color, Embed
from discord import Color, Embed, ClientException
from discord.ext import commands
from wavelink.ext import spotify

Expand Down Expand Up @@ -42,7 +43,7 @@ async def play_track(self, ctx: commands.Context, query: str, provider=None):
if not track:
return await msg.edit("No song/track found with given query.")

await msg.edit(content=f"Added {track.title} to queue")
await msg.edit(content=f"Added `{track.title}` to queue. ")
await player.queue.put(track)

await player.do_next()
Expand All @@ -69,7 +70,11 @@ async def connect(self, ctx: commands.Context):

msg = await ctx.send(f"Connecting to **`{ctx.author.voice.channel}`**")

player: DisPlayer = await ctx.author.voice.channel.connect(cls=DisPlayer)
try:
player: DisPlayer = await ctx.author.voice.channel.connect(cls=DisPlayer)
except (asyncio.TimeoutError, ClientException):
return await msg.edit(content="Failed to connect to voice channel.")

player.bound_channel = ctx.channel
player.bot = self.bot

Expand Down Expand Up @@ -121,6 +126,7 @@ async def volume(self, ctx: commands.Context, vol: int, forced=False):
return await ctx.send("Volume can't greater than 100")

await player.set_volume(vol)
await ctx.send(f"Volume set to {vol} :loud_sound:")

@commands.command(aliases=["disconnect", "dc"])
@voice_channel_player()
Expand All @@ -129,7 +135,7 @@ async def stop(self, ctx: commands.Context):
player: DisPlayer = self.bot.players[ctx.guild.id]

await player.destroy(ctx.guild.id)
await ctx.send("Stopped the player")
await ctx.send("Stopped the player :stop_button: ")

@commands.command()
@voice_channel_player()
Expand All @@ -142,7 +148,7 @@ async def pause(self, ctx: commands.Context):
return await ctx.send("Player is already paused.")

await player.set_pause(pause=True)
return await ctx.send("Player is now paused.")
return await ctx.send("Paused :pause_button: ")

await ctx.send("Player is not playing anything.")

Expand All @@ -157,7 +163,7 @@ async def resume(self, ctx: commands.Context):
return await ctx.send("Player is already playing.")

await player.set_pause(pause=False)
return await ctx.send("Player is now playing.")
return await ctx.send("Resumed :musical_note: ")

await ctx.send("Player is not playing anything.")

Expand Down Expand Up @@ -189,7 +195,7 @@ async def seek(self, ctx: commands.Context, seconds: int):
position = 0

await player.seek(position * 1000)
return await ctx.send(f"Seeked to {seconds} seconds.")
return await ctx.send(f"Seeked to {seconds} seconds :fast_forward: ")

await ctx.send("Player is not playing anything.")

Expand All @@ -200,7 +206,7 @@ async def loop(self, ctx: commands.Context, loop_type: str = None):
player: DisPlayer = self.bot.players[ctx.guild.id]

result = await player.set_loop(loop_type)
await ctx.send(f"Loop has been set to {result}")
await ctx.send(f"Loop has been set to {result} :repeat: ")

@commands.command(aliases=["q"])
@voice_channel_player()
Expand Down

0 comments on commit a1e1dac

Please sign in to comment.