首先,我正在尝试编辑机器人日志消息。基本上,该代码可以工作并且记录消息已被编辑,但是这会在终端中引起一些问题:
discord.errors.HTTPException: 400 BAD REQUEST (error code: 50035): Invalid Form Body
In embed.fields.0.value: This field is required
In embed.fields.1.value: This field is required
这是我的代码:
@client.event
async def on_message_edit(before, after):
editembed = discord.Embed(
timestamp=after.created_at,
description = f"<@!{before.author.id}>**'s message was edited in** <#{before.channel.id}>.",
colour = discord.Colour(0x00FF00)
)
editembed.set_author(name=f'{before.author.name}#{before.author.discriminator}', icon_url=before.author.avatar_url)
editembed.set_footer(text=f"Author ID:{before.author.id} • Message ID: {before.id}")
editembed.add_field(name='Before:', value=before.content, inline=False)
editembed.add_field(name="After:", value=after.content, inline=False)
channel = client.get_channel(665307525897519105)
await channel.send(embed=editembed)
我不明白为什么它决定value
为空。有人可以帮助解决这些错误吗?
答案 0 :(得分:0)
我遇到了同样的问题,但是我在Google上搜索了一段时间,找到了一个解决方案,即在+ "\u200b"
和value=before.content
之后都添加value=after.content
。我还使用了embed而不是editembed。所以试试这个:
@bot.event
async def on_message_edit(before, after):
embed = discord.Embed(
timestamp=after.created_at,
description = f"<@!{before.author.id}>**'s message was edited in** <#{before.channel.id}>.",
colour = discord.Colour(0x00FF00)
)
embed.set_author(name=f'{before.author.name}#{before.author.discriminator}', icon_url=before.author.avatar_url)
embed.set_footer(text=f"Author ID:{before.author.id} • Message ID: {before.id}")
embed.add_field(name='Before:', value=before.content + "\u200b", inline=False)
embed.add_field(name="After:", value=after.content + "\u200b", inline=False)
channel = bot.get_channel(665307525897519105)
await channel.send(embed=embed)
链接到对我有帮助的github页面:https://github.com/Rapptz/discord.py/issues/643
答案 1 :(得分:-1)
您使用了错误的变量,请尝试以下操作:
@bot.event
async def on_message_edit(before, after):
embed = discord.Embed(
timestamp=after.created_at,
description = f"<@!{before.author.id}>**'s message was edited in** <#{before.channel.id}>.",
colour = discord.Colour(0x00FF00)
)
embed.set_author(name=f'{before.author.name}#{before.author.discriminator}', icon_url=before.author.avatar_url)
embed.set_footer(text=f"Author ID:{before.author.id} • Message ID: {before.id}")
embed.add_field(name='Before:', value=before.content, inline=False)
embed.add_field(name="After:", value=after.content, inline=False)
channel = bot.get_channel(665307525897519105)
await channel.send(embed=embed)