问题描述
我正在用Discord.py做一个机器人,尝试发送带有嵌入的消息时,我不断收到错误消息。
I'm making a bot with Discord.py and I keep getting an error when trying to send a message with an embed.
这是我得到的错误:
Traceback (most recent call last):
File "C:\Users\pc\Documents\Storage\python\NanoBot\bot.py", line 101, in on_message
await client.send_message(message.channel, embed=embed)
File "C:\Users\pc\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\client.py", line 1152, in send_message
data = yield from self.http.send_message(channel_id, content, guild_id=guild_id, tts=tts, embed=embed)
File "C:\Users\pc\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\http.py", line 198, in request
raise HTTPException(r, data)
discord.errors.HTTPException: BAD REQUEST (status code: 400)
我的代码:
embed = discord.Embed(color=target.color)
embed.set_thumbnail(url=target.avatar_url)
embed.set_author(name=str(target.name), url="Playing " + str(target.game))
embed.set_footer(text="!!userinfo command")
embed.add_field(name="Status", value=str(target.status))
embed.add_field(name="Nickname", value=str(target.nick))
embed.add_field(name="Account Created", value=str(target.created_at))
embed.add_field(name="Roles", value=str(roles))
embed.add_field(name="Joined at", value=str(target.joined_at))
await client.send_message(message.channel, embed=embed)
推荐答案
由于您使用的是Discord API,因此,如果您阅读 client.send_message $的说明, c $ c>,如果您在
embed
中嵌入消息的时间超过2000 chrs,则不和谐会引发400请求错误。对于Discord的字符数限制为2000。
Since you're using discord api, if you read the description of client.send_message
, if you send a message in the embed
is longer than 2000 chrs, discord will raise a 400 request error. For Discord's character limit is 2000.
如您所见,它实际上不是真正的错误, discord.errors.HTTPException:BAD REQUEST(状态代码:400)
。这是Discord API犯下的自定义错误。要更正它,您可以将邮件拆分为少于2000 chrs的嵌入,然后分别发送。需要明确的是,不是是因为服务器已关闭,而是因为服务器由于时间过长而拒绝发送您的消息。
As you can see, it's not actually a real error, discord.errors.HTTPException: BAD REQUEST (status code: 400)
. It's a custom error made by discord API. To correct it, you can split the message into embeds that has less than 2000 chrs and send them separately. To be clear, this isn't because that the server is down, but because the server rejected to send your message since it's too long.
这篇关于由于“ BAD REQUEST”,消息未发送。与discord.py的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!