【问题标题】:discord.errors.HTTPException: BAD REQUEST (status code: 400)discord.errors.HTTPException:错误请求(状态代码:400)
【发布时间】:2017-08-10 02:34:37
【问题描述】:

我的代码使用此命令偶尔会收到 400 bad request 错误:

@owner_only
async def cmd_bootybomb(self, user_mentions, channel):
    userid = (str(user_mentions))
    await self.send_message(discord.Object(id = userid), bootybomb) 

变量bootybomb 已从另一个文件导入,该文件只是一组设置为一个变量的链接。

我得到的错误是:

Traceback (most recent call last):
  File "C:\Users\pc\Desktop\Gamefolders\BootyBot\BootyBot\musicbot\bot.py", line 1289, in on_message
    response = await handler(**handler_kwargs)
  File "C:\Users\pc\Desktop\Gamefolders\BootyBot\BootyBot\musicbot\bot.py", line 115, in wrapper
    return await func(self, *args, **kwargs)
  File "C:\Users\pc\Desktop\Gamefolders\BootyBot\BootyBot\musicbot\bot.py", line 877, in cmd_bootybomb
    await self.send_message(discord.Object(id = userid), bootybomb)
  File "C:\Users\pc\AppData\Local\Programs\Python\Python35\lib\site-packages\discord\client.py", line 831, in send_message
    data = yield from self.http.send_message(channel_id, content, guild_id=guild_id, tts=tts)
  File "C:\Users\pc\AppData\Local\Programs\Python\Python35\lib\site-packages\discord\http.py", line 137, in request
    raise HTTPException(r, data)
discord.errors.HTTPException: BAD REQUEST (status code: 400)

为什么会发生这种情况以及如何解决?

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    由于您使用的是 discord api,如果您阅读 send_message 的描述,如果您发送的消息超过 2000 chrs,discord 会引发 400 请求错误。因为 Discord 的字符限制是 2000。如您所见,它实际上并不是一个真正的错误,discord.errors.HTTPException: BAD REQUEST (status code: 400)。这是不和谐 API 造成的自定义错误。

    client.send_message: 引发:HTTPException – 发送消息失败。

    而且我前段时间也问过支持,关于这个问题,这是他们给我的解释。基本上,您必须将消息的字符保持在 2000 以下。

    这是导致此问题的最常见原因。但是,如果您的问题仍然存在,解决此问题的最佳选择是加入 discord.py API 的支持服务器,并告诉他们您的问题。因为这主要是 API 问题,而不是 python 问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-21
      • 2019-09-13
      • 2017-09-07
      • 2015-04-01
      • 1970-01-01
      • 2018-08-09
      相关资源
      最近更新 更多