如何生成spotify命令?

2024-09-28 22:29:12 发布

您现在位置:Python中文网/ 问答频道 /正文

Spotify命令

我试了很多东西,但都没能成功

@client.command()
async def spotify(ctx, user: discord.Member = None):
        embedspotify = discord.Embed(title=f"{user.name}'s Spotify", color=0x1eba10)
        embedspotify.add_field(name="Song", value=Spotify.title)
        embedspotify.add_field(name="Artist", value=Spotify.artist)
        embedspotify.add_field(name="Album", value=Spotify.album)
        embedspotify.set_thumbnail(url=Spotify.album_cover_url)

我正在尝试获取spotify歌曲的标题、艺术家的名字和我使用命令的人的专辑的名字(当他们在听spotify时)


Tags: name命令clientaddurlfieldalbumtitle
1条回答
网友
1楼 · 发布于 2024-09-28 22:29:12

您需要从Member正在执行的活动列表中获取^{}实例:

@client.command()
@commands.guild_only() # We can only access activities from a guild
async def spotify(ctx, user: discord.Member = None):
    user = user or ctx.author  # default to the caller
    spot = next((activity for activity in user.activities if isinstance(activity, discord.Spotify)), None)
    if spot is None:
        await ctx.send(f"{user.name} is not listening to Spotify")
        return
    embedspotify = discord.Embed(title=f"{user.name}'s Spotify", color=0x1eba10)
    embedspotify.add_field(name="Song", value=spot.title)
    embedspotify.add_field(name="Artist", value=spot.artist)
    embedspotify.add_field(name="Album", value=spot.album)
    embedspotify.set_thumbnail(url=spot.album_cover_url)
    await ctx.send(embed=embedspotify)

相关问题 更多 >