discord-php / DiscordPHP

An API to interact with the popular messaging app Discord
MIT License
992 stars 236 forks source link

getPermissions() undefined method error #1217

Closed slicybt3w closed 4 months ago

slicybt3w commented 5 months ago

Screenshot from 2024-04-15 18-46-23 PHP Discord: 7.3.5 PHP version: 8.1

i'm trying to get users permissions and use an if statement to see if the user has this permission or not but i keep getting this error

Error: `PHP Fatal error: Uncaught Error: Call to undefined method Discord\Parts\Permissions\RolePermission::done() in /home/slicybtw/NetBeansProjects/PhpProject2/index.php:150 Stack trace:

0 /home/slicybtw/NetBeansProjects/PhpProject2/vendor/react/promise/src/FulfilledPromise.php(28): {closure}()

1 /home/slicybtw/NetBeansProjects/PhpProject2/index.php(153): React\Promise\FulfilledPromise->then()

2 [internal function]: {closure}()`

Code:

$discord->registerCommand("check", function(Message $message) use ($discord) { try { $guildid = $message->channel->guild_id; $guild = $discord->guilds->get("id", $guildid); $guild->members->fetch($message->author->id) ->then( function (Member $member) { $member->getPermissions()->done(function (RolePermission $permission, Message $message) { if(!$permission == "ban_members") { $message->channel->sendMessage("You Cant Use The Ban Command!"); } }); })->done(); } catch(Exception $e) { $message->channel->sendMessage($e->getMessage()); } });

any help will be appreciated

valzargaming commented 5 months ago

It's usually best to check the documentation when calling a function you're not familiar with. $member->getPermissions() does not return a promise as your code seems to assume, but rather either the expected role permission or null.

$permission  = $member->getPermissions();
valzargaming commented 4 months ago

Closed due to no response, but known fix provided.