我正在尝试获取用户的 oAuth perms,但是权限的不和谐 api 对我来说太混乱了,我希望能够踢和禁止的用户能够使用我正在构建的网络面板,但就像如果我想要它的权限一样,它给了我 2 = 踢 4 = 禁止 2+4 = 6 ...我真的不明白这一点,因为您也可以用其他烫发获得 6 个烫发,我该如何压缩它?
我已经能够获得权限和服务器名称,现在缺少的主要部分是权限。
<?php
require __DIR__ . '/vendor/autoload.php';
use XwilargDiscordOAuth2;
// 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:
我最终创立了面具。 https://www.php.net/manual/en/language.operators.bitwise.php
例如,您获得的权限 ID 为 67 = 64 + 2 + 1,它将为真
if ($a["permissions"] & "64") {
echo "Can Ban";
}