【问题标题】:Can't get discord webhook to send with json无法使用 json 发送不和谐的 webhook
【发布时间】:2021-04-30 12:55:59
【问题描述】:

我一直在尝试制作一个不和谐的 webhook,但由于某种原因,我无法发送它来挽救我的生命。我在一个 json 文件中嵌入了所有内容,并试图用 python 运行它。任何帮助将不胜感激。

json 文件:

{
    "embeds": [
      {
        "title": "Title",
        "color": 11393254,
        "fields": [
          {
            "name": "Name1",
            "value": "value1"
          },
          {
            "name": "Name2",
            "value": "value2",
            "inline": true
          },
      ],
        "footer": {
          "text": "Footer",
          "icon_url": "random image url"
        },
        "timestamp": "now",
        "thumbnail": {
          "url": "random image url"
        }
      }
    ],
    "username": "Username"
  }

python 代码:

import requests, json

with open('webhook.json') as json_file:
    data = json.load(json_file)

url = 'https://discord.com/api/webhooks/xxxxx'
headers={"Content-Type": "application/json"}

requests.post(url, data=json.dumps(data), headers=headers)

【问题讨论】:

  • 我知道@Arthur Borshenko 问过这个问题,但你返回的是什么状态码?
  • 就是这样 - 在我运行它之后,我没有收到任何错误。它运行顺利,但只是没有发送到我的不和谐。 webhook 链接有效

标签: python json discord


【解决方案1】:

您从 POST 返回的状态代码是什么?这可能是它出错的线索。

【讨论】:

  • 请将操作评论的问题放在主要问题下方。
  • @SpectralWave,他没有足够的代表来做到这一点,但我很确定。
  • @SpectralWave - 希望我能,我没有足够的代表。假设我在获得所需金额之前不应该尝试回答。
  • 就是这样 - 在我运行它之后,我没有收到任何错误。它运行顺利,但只是没有发送到我的不和谐。 webhook 链接有效
  • @Brian,问题是请求不一定会出错。您需要检查 HTTP 响应。尝试将响应设置为变量并将其打印出来r = requests.post(url, data=json.dumps(data), headers=headers)print(r)
猜你喜欢
  • 2020-03-31
  • 2021-06-03
  • 2021-05-28
  • 2023-02-15
  • 2021-11-06
  • 1970-01-01
  • 2021-04-07
  • 2021-10-07
  • 2021-05-19
相关资源
最近更新 更多