<p>制作一个保存所有数据的列表,然后使用<code>.join()</code>发送它</p>
<p>我建议使用<code>f string</code>来简化字符串</p>
<p>另一种方法是将数据保存到单独的变量中,以嵌入3列</p>
<pre class="lang-py prettyprint-override"><code>@client.command(name="ukmusic")
async def playlist(ctx):
#Authortization for API usage
headers = {
"Authorization": "Bearer {}".format(oauth)
}
#These create the link that the program fetches (The playlist)
endpoint = "https://api.spotify.com/v1/playlists/37i9dQZEVXbLnolsZ8PSNw"
data = urlencode({"market": "GB"})
lookup_url = f"{endpoint}?{data}"
#This prints what the link looks like and the status code (200 if it works correctly)
print (lookup_url)
r = requests.get(lookup_url, headers = headers)
print (r.status_code)
#This prints out the playlist
em = discord.Embed(title = "Here is what the good people of Britiania are listening to on Spotify")
tracks_names = []
tracks_artists = []
tracks_album = []
# save the data into lists (could be better using a dict with a nested list
for item in r.json()['tracks']['items']:
tracks_names.append(item['track']['name'])
tracks_artists.append(item['track']['artists'][0]['name'])
tracks_album.append(item['track']['album']['name'])
# add the 3 columns
em.add_field(name="Song", value='\n'.join(tracks_names), inline=True)
em.add_field(name="Artist", value='\n'.join(tracks_artists), inline=True)
em.add_field(name="Album", value='\n'.join(tracks_album), inline=True)
await ctx.send(embed=em)
</code></pre>