【问题标题】:Discord Oauth get permissionsDiscord Oauth 获取权限
【发布时间】:2019-12-17 05:53:03
【问题描述】:

我正在尝试获取用户的 oAuth 权限,但是权限的不和谐 api 让我感到非常困惑,我希望能够踢和禁止的用户能够使用我正在构建的 Web 面板,但就像如果我想要它给我的权限 2 = 踢 4 = 禁止 2+4 = 6 ...我真的不明白这一点,因为你也可以通过其他烫发获得 6 我如何计算它?

我已经能够获得权限和服务器名称,现在主要缺少的是权限。

<?php
require __DIR__ . '/vendor/autoload.php';
use Xwilarg\Discord\OAuth2;
// Sample configuration file, contains the following strings:
// clientId: Client ID of the application
// secret: Secret of the application
// url: The redirect URL (URL called after the user is logged in, must be registered in https://discordapp.com/developers/applications/[YourAppId]/oauth)
$auth = json_decode(file_get_contents('token.json'), true);
$oauth2 = new OAuth2($auth["clientId"], $auth["secret"], $auth["url"]);
if ($oauth2->isRedirected() === false) { // Did the client already logged in ?
    // The parameter can be a combination of the following: connections, email, identity or guilds
    // More information about it here: https://discordapp.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes
    $oauth2->startRedirection(['identify', 'guilds']);
} else {
    // If preload the token to see if everything happen without error
    $ok = $oauth2->loadToken();
    if ($ok !== true) {
        // A common error can be to reload the page because the code returned by Discord would still be present in the URL
        // If this happen, isRedirected will return true and we will come here with an invalid code
        // So if there is a problem, we redirect the user to Discord authentification
        $oauth2->startRedirection(['identify', 'connections']);
    } else {
        // ---------- USER INFORMATION
        $answer = $oauth2->getUserInformation(); // Same as $oauth2->getCustomInformation('users/@me')
        if (array_key_exists("code", $answer)) {
            exit("An error occured: " . $answer["message"]);
        } else {
            echo "Welcome " . $answer["username"];
        }
        echo '<br/><br/>';
        // ---------- CONNECTIONS INFORMATION
        $answer = $oauth2->getGuildsInformation();
        if (array_key_exists("code", $answer)) {
            exit("An error occured: " . $answer["message"]);
        } else {
            foreach ($answer as $a) {
                echo $a["permissions"] . ': ' . $a["name"] . '<br/>';
            }
        }
    }
}
?>

如果我可以根据权限限制用户,我会非常喜欢,

是的,我看了不和谐的 api 文档 c:

【问题讨论】:

    标签: php oauth-2.0 composer-php discord


    【解决方案1】:

    我终于用面具创立了。 https://www.php.net/manual/en/language.operators.bitwise.php

    例如,您获得的权限 id 为 67 = 64 + 2 + 1 它会为真

    if ($a["permissions"] & "64") {
       echo "Can Ban";
    }
    
    

    【讨论】:

      猜你喜欢
      • 2017-09-27
      • 2022-01-01
      • 1970-01-01
      • 2019-10-24
      • 1970-01-01
      • 1970-01-01
      • 2019-04-22
      • 1970-01-01
      • 2021-12-18
      相关资源
      最近更新 更多