将用户添加到不和谐的公会中会产生未经许可的错误

时间:2019-08-20 18:05:26

标签: php discord

编辑:我想知道我添加的机器人错误吗?该漫游器与用户的OAuth 2位于同一应用程序上。该漫游器添加有: https://discordapp.com/oauth2/authorize?client_id= {my id}&scope = bot&permissions = 267906503

我使用https://github.com/wohali/oauth2-discord-new与Discord建立了OAuth2连接,这将返回discord用户和我的访问令牌。它具有以下作用域:

   $authUrl = $this->provider->getAuthorizationUrl([
      'scope' => [
        'identify',
        'email',
        'guilds.join']
      ]);

使用相同的不和谐应用程序,我设置了一个漫游器。该机器人是公会的成员,并且该机器人对聊天ping做出响应(这意味着它正在工作)。该机器人具有创建即时邀请权限。

在我让不和谐的用户回来并刚刚生成访问令牌之后,我正试图将该用户添加到公会中。

我已经尝试过使用restcord库,然后直接使用guzzle。

    $guzzle = new Client(['base_uri' => 'https://discordapp.com/api/v6']);

    $guildId = $this->discordApplication->guildId();
    $request = new Request('PUT', 'https://discordapp.com/api/v6/guilds/'.$guildId.'/members/'.$user->discordId(), [
      'Authorization' => 'Bot '.$this->discordApplication->accessToken()->__toString(),
      "Content-Type" => "application/json"
    ] );
    var_dump($request);
    $response = $guzzle->send($request);
    var_dump($response);

正在生成401错误。我查看了herehere以确保我的内容类型正确,授权标头正确,OAuth范围正确以及机器人权限正确。

输出为:

object(GuzzleHttp\Psr7\Request)#82 (7) {
  ["method":"GuzzleHttp\Psr7\Request":private]=>
  string(3) "PUT"
  ["requestTarget":"GuzzleHttp\Psr7\Request":private]=>
  NULL
  ["uri":"GuzzleHttp\Psr7\Request":private]=>
  object(GuzzleHttp\Psr7\Uri)#83 (7) {
    ["scheme":"GuzzleHttp\Psr7\Uri":private]=>
    string(5) "https"
    ["userInfo":"GuzzleHttp\Psr7\Uri":private]=>
    string(0) ""
    ["host":"GuzzleHttp\Psr7\Uri":private]=>
    string(14) "discordapp.com"
    ["port":"GuzzleHttp\Psr7\Uri":private]=>
    NULL
    ["path":"GuzzleHttp\Psr7\Uri":private]=>
    string(60) "/api/v6/guilds/{right guild id}/members/{the right user id}"
    ["query":"GuzzleHttp\Psr7\Uri":private]=>
    string(0) ""
    ["fragment":"GuzzleHttp\Psr7\Uri":private]=>
    string(0) ""
  }
  ["headers":"GuzzleHttp\Psr7\Request":private]=>
  array(3) {
    ["Host"]=>
    array(1) {
      [0]=>
      string(14) "discordapp.com"
    }
    ["Authorization"]=>
    array(1) {
      [0]=>
      string(34) "Bot {my oauth2 bearer access token}"
    }
    ["Content-Type"]=>
    array(1) {
      [0]=>
      string(16) "application/json"
    }
  }
  ["headerNames":"GuzzleHttp\Psr7\Request":private]=>
  array(3) {
    ["authorization"]=>
    string(13) "Authorization"
    ["content-type"]=>
    string(12) "Content-Type"
    ["host"]=>
    string(4) "Host"
  }
  ["protocol":"GuzzleHttp\Psr7\Request":private]=>
  string(3) "1.1"
  ["stream":"GuzzleHttp\Psr7\Request":private]=>
  NULL
}
Client error: `PUT https://discordapp.com/api/v6/guilds/{guildid}/members/{userid}` resulted in a `401 UNAUTHORIZED` response:
{"code": 0, "message": "401: Unauthorized"}

1 个答案:

答案 0 :(得分:1)

我知道了。


df1 = df1[df1['Computer Name'] != 'someNameToBeDropped']