使用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响应截图


Postman设置截图



相关文档:Discord 开发者文档 - 添加公会成员
已尝试的排查操作:
- 移除请求体仍返回400错误
- 移除请求头则返回401未授权
- 硬编码Postman中可用的有效值也仍返回400错误
期望得到204无内容或201带公会成员信息的响应。
内容的提问来源于stack exchange,提问作者Nigel Christiaans
相关产品推荐
相关产品推荐

