Skip to content

Commit

Permalink
Fixed error when track is not found.
Browse files Browse the repository at this point in the history
  • Loading branch information
jokelbaf committed Mar 9, 2023
1 parent 0f29950 commit 5d2f08c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
SanyaBot configuration. Includes texts for descriptions,
images, Bot configuration like «Developer Mode» and
some permament data like links and credentials.
some permanent data like links and credentials.
"""

import discord, os
Expand Down
42 changes: 27 additions & 15 deletions cogs/Music.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,26 @@ async def player_play(self, ctx: commands.Context, *, song: str = None):
else:
try:
song = await wavelink.YouTubeTrack.search(query=song, return_first=True)
await vc.message.edit(
embed=Embeds.Music.music_player_connected(vc.language, song, ctx)
)
await ctx.reply(
embed=Embeds.Music.track_added_ctx(user.language, ctx, song), mention_author=False
)
await vc.play(song)
except:
return await ctx.reply(
embed=Embeds.Music.song_not_found(user.language), mention_author=False
)
await vc.message.edit(
embed=Embeds.Music.music_player_connected(vc.language, song, ctx)
)
await ctx.reply(
embed=Embeds.Music.track_added_ctx(user.language, ctx, song), mention_author=False
)
await vc.play(song)

await ctx.guild.change_voice_state(channel=ctx.author.voice.channel, self_deaf=True, self_mute=False)
else:
song = await wavelink.YouTubeTrack.search(query=song, return_first=True)
try:
song = await wavelink.YouTubeTrack.search(query=song, return_first=True)
except:
return await ctx.reply(
embed=Embeds.Music.song_not_found(user.language), mention_author=False
)
await vc.queue.put_wait(song)
await ctx.reply(
embed=Embeds.Music.track_added_ctx(user.language, ctx, song), mention_author=False
Expand Down Expand Up @@ -713,7 +718,12 @@ async def play(self, ctx: discord.ApplicationContext, song: str):
)
else:
try:
song = await wavelink.YouTubeTrack.search(query=song, return_first=True)
try:
song = await wavelink.YouTubeTrack.search(query=song, return_first=True)
except:
return await ctx.followup.send(
embed=Embeds.Music.song_not_found(user.language)
)
await vc.message.edit(
embed=Embeds.Music.music_player_connected(vc.language, song, ctx)
)
Expand All @@ -722,16 +732,18 @@ async def play(self, ctx: discord.ApplicationContext, song: str):
)
await vc.play(song)
except:
msg = await ctx.followup.send(
embed=Embeds.Music.choose_platform(user.language)
return await ctx.followup.send(
embed=Embeds.Music.song_not_found(user.language)
)
await msg.edit(view=Views.PlayersMenu(self.bot, ctx, msg, song))
setattr(vc, "message_id", msg.id)
setattr(vc, "message", msg)

await ctx.guild.change_voice_state(channel=ctx.author.voice.channel, self_deaf=True, self_mute=False)
else:
song = await wavelink.YouTubeTrack.search(query=song, return_first=True)
try:
song = await wavelink.YouTubeTrack.search(query=song, return_first=True)
except:
return await ctx.followup.send(
embed=Embeds.Music.song_not_found(user.language)
)
await vc.queue.put_wait(song)
await ctx.followup.send(
embed=Embeds.Music.track_added_ctx(user.language, ctx, song)
Expand Down

0 comments on commit 5d2f08c

Please sign in to comment.