首页 > 解决方案 > 使用 guilds.join 请求让用户加入不和谐公会

问题描述

代码:

let response = await fetch(
    `https://discord.com/api/guilds/877414872068001853/members/[user id]`,
    {
        method: 'PUT',
        access_token: `Bearer [user access code]`,
        headers: {
            "Authorization": `Bot [bot token]`,
            "Content-Type": "application/json"
        }
    }
);
console.log(response);

错误

Response {
    size: 0,
    timeout: 0,
    [Symbol(Body internals)]: { body: [PassThrough], disturbed: false, error: null },
    [Symbol(Response internals)]: {
      url: 'https://discord.com/api/guilds/877414872068001853/members/522503261941661727',
      status: 400,
      statusText: 'Bad Request',
      headers: [Headers],
      counter: 0
    }
}

标签: discorddiscord.js

解决方案


感谢@user15517071

我的access_token不在正文中,而且我使用的“访问令牌”只是来自discord oauth的重定向令牌,所以我需要使用实际的访问令牌discord在获取用户详细信息后为您提供,它可以工作。

{
 method: 'PUT',
 body: JSON.stringify({
   access_token: `Bearer User_AccessToken`,
 }),
 headers: {
  "Authorization": `Bot Bot_Token`,
  "Content-Type": "application/json"
 }
};

推荐阅读