繁体   English   中英

如何将 Json 文件中的所有名称写入 discord.py 中的一个值和一个标题

[英]How to write all names from Json file in discord.py embed in one value with one title

我的代码

@Bot.command()
async def nicknames(ctx, *, message:str=None):

   embed = discord.Embed(title=f"Profile Details", description="nicknames", 
   color=discord.Color.green())
   uuid = MojangAPI.get_uuid(f"{message}")
   profile = MojangAPI.get_profile(uuid)
   people = requests.get('https://api.mojang.com/user/profiles/' + uuid + '/names' )
   people_json  = people.json()
   length = len(people_json)
   for length in range(length):
      embed.add_field(name="nicknames", value=people_json[length]["name"], inline=True)

   await ctx.send(embed=embed)

在此处输入图像描述代码结果,但我需要一个值和一个标题中的所有名称在此处输入图像描述

在这里我找到了我的代码的结果如何将 json 文件传输到 discord.py 上的嵌入中? 但是代码不起作用

要在字符串中开始新行,请使用\n 这意味着

print("First Line!\nSecond Line")

输出

First Line!
Second Line

您可以使用它来获取一个字段中的昵称:

names = ""
for i in range(length):
    names = names + "\n" + people_json[i]["name"] #add \n and the person to the string
embed.add_field(name="Nicknames", value = names, inline=True) #add the field

暂无
暂无

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

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