You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Node.js V18 Fetch调用Discord API返回400错误,Postman可正常请求

问题:Node.js V18 Fetch调用Discord接口返回400 Bad Request,Postman请求正常

以下是Node.js V18中的Fetch代码:

let response = await fetch(`https://discord.com/api/guilds/${guild_id}/members/${user_id}`, {
        method: "PUT",
        headers: {
            "authorization": `Bot ${bot_token}`,
            "Content-Type": "application/json"
        },
        body: JSON.stringify({
            access_token: access_token,
        }),
    });

调用该接口时返回400 Bad Request,但相同请求在Postman中能得到预期的204无内容响应。

Fetch响应截图

fetch response
Fetch response smaller

Postman设置截图

postman body
Postman header
Response

相关文档:Discord 开发者文档 - 添加公会成员

已尝试的排查操作:

  • 移除请求体仍返回400错误
  • 移除请求头则返回401未授权
  • 硬编码Postman中可用的有效值也仍返回400错误

期望得到204无内容或201带公会成员信息的响应。

内容的提问来源于stack exchange,提问作者Nigel Christiaans

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 10:01:43