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时)
答案 0 :(得分:0)
您需要从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)
答案 1 :(得分:0)
命令效果很好,我决定通过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')```