0xwaleed / discorole
检查用户的角色和权限
0.1.2
2022-04-01 13:42 UTC
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7.3.0
- psr/simple-cache: ^1.0
Requires (Dev)
- pestphp/pest: ^1.20
- pestphp/pest-plugin-mock: ^1.0
README
DiscoRole
一个简单的PHP库,用于从指定的公会获取所有用户的角色和权限。
目的
有时我会构建一个应用程序,并希望将用户与其角色在应用程序和我的Discord服务器之间进行同步,以便在一个地方管理角色。
要求
- PHP 8 <3
- 机器人令牌,并且机器人应位于您的服务器上
安装
composer require 0xwaleed/discorole
示例
当您需要检查成员的角色/权限时
use DiscoRole\PermissionConstants; $d = new \DiscoRole\DiscoRole(token: 'your bot token'); $guild = $d->getGuild('guild id here'); $member = $guild->getMember('member id here'); //if we want to check for specific role if ($member->has('role id')) { //do your logic } //if we want to traverse all member's roles and check if one of them //has the these permissions if ($member->has(PermissionContatns::MANAGE_MESSAGES | PermissionContatns::MANAGE_GUILD)) { //do your logic }
当您想要获取角色详细信息时
foreach ($member->roles as $role) { $role->id; $role->name; $role->color; ... }