gpt4 book ai didi

python-3.x - discord webhook 无法发送空消息

转载 作者:行者123 更新时间:2023-12-04 01:52:02 25 4
gpt4 key购买 nike

我已经为 discord webhooks 编写了这个小 PoC,但我收到了无法发送空字符串的错误。我试图用谷歌搜索但找不到文档或答案

这是我的代码

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)

最佳答案

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

在大多数情况下,这主要是由于有效载荷的结构错误。

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

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

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

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

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

    关于python-3.x - discord webhook 无法发送空消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52565121/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com