@@ -145,19 +145,17 @@ async def search(self, interaction: discord.Interaction, keyword: str):
145145 view = SearchSelectView (self , tracks , interaction ),
146146 )
147147
148- @app_commands .command (name = "shuffle" , description = "Shuffle" )
149- @app_commands .describe (ephemeral = "hide response" )
150- async def shuffle (self , interaction : discord .Interaction , ephemeral : bool = False ):
148+ async def do_shuffle (self , interaction : discord .Interaction , ephemeral : bool = False ):
149+ """Helper method to shuffle the queue"""
151150 await self .ensure_subscription (interaction )
152151 subscription = self .subscriptions .get (interaction .guild_id )
153152 random .shuffle (subscription .queue )
154153 await interaction .response .send_message (
155154 embed = SuccessEmbed (self .bot .user , "Shuffle complete" ), ephemeral = ephemeral
156155 )
157156
158- @app_commands .command (name = "skip" , description = "Skip to next song" )
159- @app_commands .describe (ephemeral = "hide response" )
160- async def skip (self , interaction : discord .Interaction , ephemeral : bool = False ):
157+ async def do_skip (self , interaction : discord .Interaction , ephemeral : bool = False ):
158+ """Helper method to skip to the next song"""
161159 await self .ensure_subscription (interaction )
162160 await interaction .response .defer (ephemeral = ephemeral )
163161 subscription = self .subscriptions .get (interaction .guild_id )
@@ -173,6 +171,16 @@ async def skip(self, interaction: discord.Interaction, ephemeral: bool = False):
173171 embed = SuccessEmbed (self .bot .user , "No song left" )
174172 )
175173
174+ @app_commands .command (name = "shuffle" , description = "Shuffle" )
175+ @app_commands .describe (ephemeral = "hide response" )
176+ async def shuffle (self , interaction : discord .Interaction , ephemeral : bool = False ):
177+ await self .do_shuffle (interaction , ephemeral )
178+
179+ @app_commands .command (name = "skip" , description = "Skip to next song" )
180+ @app_commands .describe (ephemeral = "hide response" )
181+ async def skip (self , interaction : discord .Interaction , ephemeral : bool = False ):
182+ await self .do_skip (interaction , ephemeral )
183+
176184 @app_commands .command (name = "leave" , description = "Leave current channel" )
177185 async def leave (self , interaction : discord .Interaction ):
178186 await self .ensure_subscription (interaction )
@@ -215,13 +223,16 @@ async def updateNowPlaying(self, guild_id, message_id):
215223 if not subscription :
216224 self .updateNowPlaying .cancel ()
217225 if subscription and not subscription .checkLock :
218- message = self .bot .get_message (message_id )
219- if message :
220- await message .edit (
221- embed = NowPlayingEmbed (
222- track = subscription .nowPlaying , queue = subscription .queue
226+ try :
227+ message = await subscription .messageChannel .fetch_message (message_id )
228+ if message :
229+ await message .edit (
230+ embed = NowPlayingEmbed (
231+ track = subscription .nowPlaying , queue = subscription .queue
232+ )
223233 )
224- )
234+ except discord .NotFound :
235+ self .updateNowPlaying .cancel ()
225236
226237 async def ensure_voice (self , interaction : discord .Interaction ):
227238 voice_client = interaction .guild .voice_client if interaction .guild else None
@@ -343,9 +354,14 @@ def __init__(
343354 self .original_interaction = interaction
344355
345356 async def callback (self , interaction : discord .Interaction ):
357+ # Find the "Top" toggle button by custom_id
358+ top_button = next (
359+ (item for item in self .view .children if getattr (item , 'custom_id' , None ) == "Top" ),
360+ None
361+ )
346362 top = (
347363 True
348- if self . view . get_item ( "Top" ) .style == discord .ButtonStyle .success
364+ if top_button and top_button .style == discord .ButtonStyle .success
349365 else False
350366 )
351367 self .view .clear_items ()
@@ -416,8 +432,8 @@ def __init__(self, player: Player):
416432 @discord .ui .button (
417433 label = "Skip" , custom_id = "skip" , style = discord .ButtonStyle .primary , emoji = "⏩"
418434 )
419- async def skip (self , button : discord .ui . Button , interaction : discord .Interaction ):
420- await self .player .skip (interaction , True )
435+ async def skip (self , interaction : discord .Interaction , button : discord .ui . Button ):
436+ await self .player .do_skip (interaction , True )
421437
422438 @discord .ui .button (
423439 label = "Shuffle" ,
@@ -426,9 +442,9 @@ async def skip(self, button: discord.ui.Button, interaction: discord.Interaction
426442 emoji = "🔀" ,
427443 )
428444 async def shuffle (
429- self , button : discord .ui . Button , interaction : discord .Interaction
445+ self , interaction : discord .Interaction , button : discord .ui . Button
430446 ):
431- await self .player .shuffle (interaction , True )
447+ await self .player .do_shuffle (interaction , True )
432448
433449 @discord .ui .button (
434450 label = "Stop Sync" ,
@@ -437,8 +453,8 @@ async def shuffle(
437453 emoji = "♾️" ,
438454 )
439455 async def stopSync (
440- self , button : discord .ui . Button , interaction : discord .Interaction
456+ self , interaction : discord .Interaction , button : discord .ui . Button
441457 ):
442458 self .player .updateNowPlaying .cancel ()
443- self .disable_all_items ()
459+ self .clear_items ()
444460 await interaction .response .edit_message (view = self )
0 commit comments