0xwaleed/discorole

Check user's roles and permissions

0.1.2 2022-04-01 13:42 UTC

This package is auto-updated.

Last update: 2024-04-07 03:17:20 UTC


README

TEST

DiscoRole

Simple PHP library to get all user's rols and permissions from the specified guild.

The Purpose

Sometimes I build an application and want to synchronize the user with his roles between my application and my Discord server in order to manage roles in one place.

Requiremensts

  • PHP 8 <3
  • Bot token and the bot should be in your server

Install

composer require 0xwaleed/discorole

Examples

When you need to check for member's roles/permissions

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
}

When you want to get role details

foreach ($member->roles as $role) {
    $role->id;
    $role->name;
    $role->color;
    ...
}