问题
@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