简体   繁体   中英

discord.py: How to use Spotify class in a embed?

I'm making a userinfo command and I have an activity section where the activity of the user is being displayed. If the activity is Spotify , I want to display the title, artist, album and album cover url.

However, my code currently isn't detecting when the user is listening to spotify.

My code:

@client.command(aliases=['whois', 'user'])
async def userinfo(ctx, member: discord.Member = None):
    if member:
       if not member.id in [674381913867288619, 716031519667388426, 711978045774233690]:
            if member.activity == None:
                activity = 'Keine'

            elif member.activity == Spotify:
                activity = 'Spotify' \
                           f'\n{member.activity.artist} - {member.activity.title}' \
                           f'\naus [{member.activity.album}]({member.activity.album_cover_url})'

            else:
                activity = f'{member.activity.name}'

            embed = discord.Embed(color=member.top_role.color.value, title=f'User-Info für {member}')
            embed.add_field(name='**Activity**', value=f'{activity}', inline=True)
            await ctx.send(embed=embed)

You'll want to check the type of the activity - this will return the object type, which you'll then be able to compare against the Spotify class:

elif type(member.activity) == discord.Spotify:
    # do some stuff

References:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM