Error 400 in discord.py

只谈情不闲聊 提交于 2020-01-03 16:37:32

问题


I'm making a bot with Discord.py and I keep getting an error when trying to send a message with an embed.

Here's the error I get:

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)

My code:

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)

回答1:


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.

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.



来源:https://stackoverflow.com/questions/43016830/error-400-in-discord-py

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