Discord webhook 无法发送空消息

Em *_* Ae 5 webhooks python-3.x discord

我已经为不和谐的 webhooks 编写了这个小 PoC,但收到Can not send empty string 的错误。我尝试谷歌但找不到文档或答案

这是我的代码

import requests

discord_webhook_url = 'https://discordapp.com/api/webhooks/xxxxxxxxxxxxxxxxxx/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

data = {'status': 'success'}
headers = {'Content-Type': 'application/json'}

res = requests.post(discord_webhook_url, data=data, headers=headers)

print(res.content)
Run Code Online (Sandbox Code Playgroud)

MrS*_*nts 8

我迟到了,但我最近遇到了这个问题,由于它还没有得到解答,我想我记录了我对该问题的解决方案。

在大多数情况下,这很大程度上是由于有效负载的结构错误造成的。

https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html提供了工作结构的示例。https://discordapp.com/developers/docs/resources/channel#create-message是官方文档。

我还能够使用以下方法获得最小测试用例{"content": "Test"}

如果之后仍然失败并出现相同的错误,可能的原因是:

  • 如果使用curl,请检查以确保没有意外转义/反斜杠\
  • 如果使用带有字段的嵌入,请确保没有空值

如有疑问,请确保填充所有值,而不是""。通过试错/取消过程,您可以准确地找出导致问题的键值对,因此我建议在将其变成完整程序之前通过curl使用webhook。