简体   繁体   English

我如何制作 Spotify 命令?

[英]How can i make a spotify command?

Spotify Command Spotify 命令

i tried a lot of things and i cant get this to work我尝试了很多东西,但我无法让它发挥作用

@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)

i am trying to get spotifytitle of the song,name of artist and name of album of the person i use command on(when they are listening to spotify)我正在尝试获取歌曲的 Spotify 标题、艺术家姓名和我使用命令的人的专辑名称(当他们正在听 Spotify 时)

You need to get the Spotify instance from the list of activities the Member is performing:您需要从Member正在执行的活动列表中获取Spotify实例:

@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)

Command works great, i decided to add in the embed the track link via track_id命令效果很好,我决定通过track_id添加嵌入轨道链接

[{spot.title}](https://open.spotify.com/track/{spot.track_id})

async def spotify(self, ctx, user: discord.Member = None):
    user = user or ctx.author  
    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
    embed = discord.Embed(title=f"{user.name}'s Spotify", color=spot.color)
    embed.add_field(name="Song", value=spot.title)
    embed.add_field(name="Artist", value=spot.artist)
    embed.add_field(name="Album", value=spot.album)
    embed.add_field(name="Track Link", value=f"[{spot.title}](https://open.spotify.com/track/{spot.track_id})")
    embed.set_thumbnail(url=spot.album_cover_url)
    await ctx.send(embed=embed)
        print(f'{user.name} in {ctx.guild} called the command !spotify')```

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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