简体   繁体   中英

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. #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) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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