【问题标题】:PowerShell Discord WebhookPowerShell Discord Webhook
【发布时间】:2021-03-24 17:32:24
【问题描述】:

我在使用此代码时遇到错误

$uri = "https://discord.com/api/webhooks/760116538895499265/yhQdNc10asfDzt8hldAJp32et1Gp_1-mvqIGPWZiAMcOwFjb5aqf7uNEF7MX6i15UKJK"

$hash = @{ "content" = "heyyy"; }

$JSON = $hash | convertto-json

Invoke-WebRequest -uri $uri -Method POST -Body $JSON
Invoke-WebRequest : {"message": "Cannot send an empty message", "code": 50006}
At line:7 char:1
+ Invoke-WebRequest -uri $uri -Method POST -Body $JSON
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

这是因为什么?

【问题讨论】:

    标签: powershell discord


    【解决方案1】:

    您应该在请求中将 Content-Type 指定为 application/json:

     Invoke-WebRequest -uri $uri -Method POST -Body $JSON -Headers @{'Content-Type' = 'application/json'}
    

    见:https://github.com/discord/discord-api-docs/issues/1210

    【讨论】:

      猜你喜欢
      • 2017-05-22
      • 2022-07-24
      • 2021-11-25
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      • 2021-01-01
      • 2020-11-26
      相关资源
      最近更新 更多