Show track length in autocomplete choices

Track autocomplete choices now display the formatted track length for both current tracks and history, improving user clarity when selecting tracks.
This commit is contained in:
Choco
2025-10-08 12:19:40 +08:00
parent 12be1ede64
commit 7479f9bfe2

View File

@@ -95,10 +95,10 @@ class Basic(commands.Cog):
if isinstance(tracks, voicelink.Playlist):
tracks = tracks.tracks
return [app_commands.Choice(name=truncate_string(f"🎵 {track.author} - {track.title}", 100), value=truncate_string(f"{track.author} - {track.title}", 100)) for track in tracks]
return [app_commands.Choice(name=truncate_string(f"🎵 [{track.formatted_length}] {track.author} - {track.title}", 100), value=track.uri) for track in tracks]
history = {track["identifier"]: track for track_id in reversed(await MongoDBHandler.get_user(interaction.user.id, d_type="history")) if (track := voicelink.Track.decode(track_id))["uri"]}
return [app_commands.Choice(name=truncate_string(f"🕒 {track['author']} - {track['title']}", 100), value=track['uri']) for track in history.values() if len(track['uri']) <= 100][:25]
return [app_commands.Choice(name=truncate_string(f"🕒 [{format_ms(track['length'])}] {track['author']} - {track['title']}", 100), value=track['uri']) for track in history.values() if len(track['uri']) <= 100][:25]
@commands.hybrid_command(name="connect", aliases=get_aliases("connect"))
@app_commands.describe(channel="Provide a channel to connect.")