【问题标题】:I keep receiving an empty message error when trying to post a webhook尝试发布 webhook 时,我不断收到空消息错误
【发布时间】:2019-07-19 15:09:25
【问题描述】:

这是我第一次使用 Discord 嵌入,更不用说制作 webhook。试图找出我做错了什么有点麻烦。希望有人可以提供帮助!

当我尝试使用此代码发送带有消息的嵌入时:

{
  "username": "Official Discord Servers",
  "avatar_url": "https://imgur.com/a/Cl3zspb",
  "embeds": [{
    "description": "Here is a list of official Discord servers maintained by our State. Note that most of these servers may restrict full access to those who are members of their respective departments:",
    "color": 16007990,
    "fields": [
      {
        "name": "State of Atoll",
        "value": "[Discord Server](https://discord.gg/5KKgb2z)"
      },
      {
        "name": "Atoll Law Enforcement Training Academy",
        "value": "[Discord Server](https://discord.gg/GJnbavz)"
      },
      {
        "name": "Atoll Department of Homeland Security",
        "value": "[Discord Server](https://discord.gg/acnPFa7)"
      },
      {
        "name": "Palm County Sheriff's Office",
        "value": "[Discord Server](https://discord.gg/uYFANDs)"
      },
      {
        "name": "Atoll State Police",
        "value": "[Discord Server](https://discord.gg/WNHKtra)"
      },
      {
        "name": "Atoll Department of Corrections",
        "value": "[Discord Server](https://discord.gg/VbFew9s)"
      },
      {
        "name": "Atoll National Guard",
        "value": "[Discord Server](https://discord.gg/6zE9HyW)"
  }]
}

我收到此错误:

{ “代码”:50006, "message": "不能发送空消息" }

【问题讨论】:

  • 即使我指定内容字段也会出现同样的问题。
  • 你能提供你的代码示例吗?
  • @IvMisticos 尝试通过 pastebin 提供您的代码示例
  • 我已经提供了解决方案,因为不再是我的问题了。

标签: discord discord.js


【解决方案1】:

您需要将“内容”作为包含正在发送的消息内容的键值对发送。

"content": "Just testing webhooks"

【讨论】:

    【解决方案2】:

    需要标头Content-Type,其值为application/json。也可以尝试设置content 字段。

    您的问题是无效的 JSON,因此请尝试使用 JSON validator

    【讨论】:

    • 如果你刚开始遇到这个问题,这是正确的答案!在我的 Curl 请求中添加 Content-Type 标头解决了我的问题。 -H "Content-Type:application/json" 谢谢!
    【解决方案3】:

    问题中提到的 JSON 无法解析,格式不正确,缺少右括号。请在下面我的答案中找到最后一组}] 括号,试试这个,

    {
      "username": "Official Discord Servers",
      "avatar_url": "https://imgur.com/a/Cl3zspb",
      "embeds": [{
        "description": "Here is a list of official Discord servers maintained by our State. Note that most of these servers may restrict full access to those who are members of their respective departments:",
        "color": 16007990,
        "fields": [
          {
            "name": "State of Atoll",
            "value": "[Discord Server](https://discord.gg/5KKgb2z)"
          },
          {
            "name": "Atoll Law Enforcement Training Academy",
            "value": "[Discord Server](https://discord.gg/GJnbavz)"
          },
          {
            "name": "Atoll Department of Homeland Security",
            "value": "[Discord Server](https://discord.gg/acnPFa7)"
          },
          {
            "name": "Palm County Sheriff's Office",
            "value": "[Discord Server](https://discord.gg/uYFANDs)"
          },
          {
            "name": "Atoll State Police",
            "value": "[Discord Server](https://discord.gg/WNHKtra)"
          },
          {
            "name": "Atoll Department of Corrections",
            "value": "[Discord Server](https://discord.gg/VbFew9s)"
          },
          {
            "name": "Atoll National Guard",
            "value": "[Discord Server](https://discord.gg/6zE9HyW)"
          }]
        }]
    }
    

    【讨论】:

    • 你好,思想家。你能澄清一下,你到底改变了什么?因为它很难比较,你知道的。
    • 你好 Misticos,请在我的回答中找到最后一个 }] 括号,无法解析问题中提到的 JSON,它缺少右括号。
    • 我知道,但你应该在 IMO 中指定答案。
    • 您好 Misticos,感谢您的建议,我现在已经更新了我的答案并提供了更多详细信息。
    【解决方案4】:

    就我而言,我在请求中直接发送纯文本而不是 JSON。然后,当我将消息更改为以下内容时,它起作用了。

    {content: "This is the message"}
    

    如果您要发送嵌入,您仍然可以将内容设置为 null。

    【讨论】:

      猜你喜欢
      • 2020-07-26
      • 2014-05-03
      • 2019-05-15
      • 2019-07-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-17
      • 1970-01-01
      • 2020-03-07
      相关资源
      最近更新 更多