Can I safely ignore these errors?

匆匆过客 提交于 2020-03-23 08:17:11

问题


@client.event
async def on_message_edit(before, after):
    channel = client.get_channel (649024513614282764)
    embed=discord.Embed(title="Edited Message", description=f"Message sent by {before.author.mention} ({before.author}) in {before.channel.mention}", color=0xffff00, timestamp=datetime.datetime.now())
    embed.add_field(name=f"{before.content}", value=f"{after.content}", inline=False)
    if channel is None:
        print("Channel not found")
    else:
        await channel.send(embed=embed)

When I run the above, it's running as intended. However it's chucking

Exception has occurred: HTTPException
400 BAD REQUEST (error code: 50035): Invalid Form Body
In embed.fields.0.name: This field is required
In embed.fields.0.value: This field is required

I'm ignoring the errors for now, since it's working. Will this cause an issue further down the line? If so, how can I fix it? Thank you.


回答1:


Your embed isn't being sent because before.content and after.content are empty strings.
Hence the error telling you that those fields are required.
The message in question is likely from a bot and only has an embed.
You can handle this by simply checking for the existence of before.content and after.content before you add the field to the embed.



来源:https://stackoverflow.com/questions/59673603/can-i-safely-ignore-these-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!