discord-php / DiscordPHP

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

feat(CommandClient): Add options for internalRejectedPromiseHandler #1210

Closed SQKo closed 3 months ago

SQKo commented 3 months ago

This PR adds 'internalRejectedPromiseHandler' in DiscordCommandClient which accepts a null or a callable, by default the library will log promise rejection caused by internal calls from the DiscordCommandClient instead of being ghosted (since the code was not maintained for 8 years). Thanks to @2colours for reporting the issue.

Example code:

$discord->registerCommand('test', function ($message) {
    return 'test';
});

This will send reply "test" to the user who used test command, or else will log the rejection errors (e.g. missing permissions). Same applies to default help command.

To override this:

$discordCommandClient = new DiscordCommandClient([
    'token' => '<secret>',
    'internalRejectedPromiseHandler' => function ($reason): void {
        // Do something
    },
    'discordOptions' => [],
]);

or set null for the old effect with ghost promise bug.