Reputation: 17
I'm making a command in discord.py rewrite and it uses a user's activity to send an embed about what they're listening to on spotify. The command works but the duration of the song is in hours, minutes, seconds, milliseconds. I'm trying to make it so that it's just minutes and seconds, how would i go about doing that? Here's my embed code and I attached an imgur link to an image of the embed at the end:
em.title = f'{user.display_name} is listening to Spotify'
em.set_thumbnail(url=activity.album_cover_url)
em.add_field(name="**Song name:**", value=activity.title, inline=False)
em.add_field(name="**Song artist:**", value=activity.artist, inline=False)
em.add_field(name="**Song Length:**", value=activity.duration, inline=False)
await ctx.send(embed=em)
https://i.sstatic.net/S89JS.png
Upvotes: 0
Views: 826
Reputation: 2540
The discord docs specify that the song duration activity.duration
is a datetime.timedelta object.
Try updating your embed code with the following divmod()
to break the activity.duration.seconds
into minutes and seconds.
em.title = f'{user.display_name} is listening to Spotify'
em.set_thumbnail(url=activity.album_cover_url)
em.add_field(name="**Song name:**", value=activity.title, inline=False)
em.add_field(name="**Song artist:**", value=activity.artist, inline=False)
m1, s1 = divmod(int(activity.duration.seconds), 60)
song_length = f'{m1}:{s1}'
em.add_field(name="**Song Length:**", value=song_length, inline=False)
await ctx.send(embed=em)
Results:
Upvotes: 1