简体   繁体   English

从json文件读取数据然后写入嵌入?

[英]reading data from json file then writing into an embed?

So I was working on a new feature on a discord bot that would tell you all the parties(clans) in the server, and the clan info is stored inside a json file, I would like to send it to the user though send_message(), but it keeps returning this error: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: BAD REQUEST (status code: 400) after a bit of research it means that there's more than 2000 characters inside the message, and I was wondering what's wrong with my code, any suggestion is welcomed, thanks for reading this. 所以我正在研究一个不和谐机器人的新功能,该功能会告诉你服务器中的所有各方(部落),并且部落信息存储在json文件中,我想通过send_message()将其发送给用户但它不断返回此错误:discord.ext.commands.errors.CommandInvokeError:命令引发异常:HTTPException:BAD REQUEST(状态代码:400)经过一些研究后意味着消息中有超过2000个字符,我想知道我的代码有什么问题,欢迎提出任何建议,感谢您阅读本文。 #I_Love_Troubleshooting #I_Love_Troubleshooting

@client.command(pass_context=True)
async def partylist(ctx):
    user = ctx.message.author
    await partylist(user)


async def partylist(user):
    partylist = discord.Embed(
        colour = discord.Colour.orange()
    )
    partylist.set_author(name="Parties")
    with open(url2, 'r') as w:
        file = json.load(w)
        for item in file:
            partylist.add_field(name=item,value="",inline=False)
    w.close()
    await client.say(user,embed=partylist)

#This is the json file
{"clan2": {"Members": "ShareYourGraves#9977"}, "clan1": {"Members": "||CATENARY||#9105,"}}

I suggest you just send a limited amount of information to the users the allow them to get more detailed info via different commands or make them view it on webpage 我建议您只是向用户发送有限的信息,允许他们通过不同的命令获取更详细的信息,或者让他们在网页上查看

data={"clan2": {"Members": "ShareYourGraves#9977"}, "clan1": {"Members": "||CATENARY||#9105,"}}

async def send_data(user):
    emb=discord.Embed(title='Data')
    clans=[name for name in data]
    emb.add_field(name='clan names',value=" ,".join(clans))
    await bot.send_message(user,embed=emb) 

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

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