gpt4 book ai didi

python - 创建特定于 api 响应中的数字的多个值

转载 作者:太空宇宙 更新时间:2023-11-03 21:39:44 24 4
gpt4 key购买 nike

因此,我需要设置与 API 响应内的数字相对应的多个值,以实现不和谐嵌入:

    {rows: 7, vbucks: "https://fortnite-public-files.theapinetwork.com/fortnite-vbucks-icon.png",…}
items: [{itemid: "d17ae35-1b64bca-f0cebef-e097b12", name: "Divine Dragon", cost: "???", item: {,…}},…]
0: {itemid: "d17ae35-1b64bca-f0cebef-e097b12", name: "Divine Dragon", cost: "???", item: {,…}}
1: {itemid: "e072f22-591edf6-1243f3d-1686821", name: "Guan Yu", cost: "???", item: {,…}}
2: {itemid: "51c5fcc-445f634-eacbd39-540174d", name: "Loyal Shield", cost: "???", item: {,…}}
3: {itemid: "a7c3fc6-75503a3-393e6cd-8ee4c91", name: "Headbanger", cost: "???",…}
4: {itemid: "88b0141-ba800b9-030f4d4-3efac45", name: "Guandao", cost: "???", item: {,…}}
5: {itemid: "8f7d376-2c49df9-ad16235-6538f87", name: "Onesie", cost: "???", item: {,…}}
6: {itemid: "3c83cd1-592e881-d91e78b-34442d8", name: "Bullseye", cost: "???", item: {,…}}
rows: 7

看看它是怎么说的rows: 7 那里有 7 个东西?我需要为每个下拉数字设置 2 个值,我需要根据 rows: 数字设置它的原因是因为它们的数量经常变化,但是我不知道如何做到这一点...这是我的代码,其中有两个值来展示我的想法:

    if unreleased in ('unreleased','upcoming'):
upcoming = fortnite_api_upcoming(unreleased)

if upcoming:
upcomingname0 = upcoming[0]['name']
upcomingtype0 = upcoming[0]['item']['type']
upcomingname1 = upcoming[1]['name']
upcomingtype1 = upcoming[1]['item']['type']

embed = discord.Embed(title="Item API Search Result", color=0xc600bc)

embed.set_footer(text="by BattleDash#3866", icon_url="https://pbs.twimg.com/profile_images/1038570723382415361/wVhgKMug_400x400.jpg")
embed.add_field(name="Unreleased Items", value='{}, **type:** {}\n'.format(upcomingname0, upcomingtype0), inline=False)
embed.add_field(name="Unreleased Items", value='{}, **type:** {}\n'.format(upcomingname1, upcomingtype1), inline=False)
await client.send_message(message.channel, embed=embed)
else:
await client.send_message(message.channel, 'Failed to get API data for unreleased items, there might be none!')

感谢任何可以提供帮助的人!

最佳答案

看起来所有这些项目都可以在 items 列表中找到。为什么不直接迭代它并使用其中的每个项目?

if upcoming:
embed = discord.Embed(title="Item API Search Result", color=0xc600bc)
embed.set_footer(text="by BattleDash#3866", icon_url="https://pbs.twimg.com/profile_images/1038570723382415361/wVhgKMug_400x400.jpg")

for item in upcoming['items']:
item_name = item['name']
item_type = item['item']['type']
embed.add_field(name="Unreleased Items", value='{}, **type:** {}\n'.format(item_name, item_type), inline=False)

await client.send_message(message.channel, embed=embed)
else:
await client.send_message(message.channel, 'Failed to get API data for unreleased items, there might be none!')

关于python - 创建特定于 api 响应中的数字的多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52961953/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com