discord-php / DiscordPHP

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

Ban user #989

Closed TigDav closed 1 year ago

TigDav commented 1 year ago

Function Ban in Discord\Parts\User\Member if daysToDeleteMessages = null, then the user is not banned.

To Reproduce

$member->ban(null, 'reason');

Expected behavior The user will be banned, the message for the last days will not be deleted.

Additional context The problem can be fixed by changing the ban function:

    public function ban(?int $daysToDeleteMessages = null, ?string $reason = null): ExtendedPromiseInterface
    {
        if (!$guild = $this->guild) {
            return reject(new \RuntimeException('Member has no Guild Part'));
        }

        return is_null($daysToDeleteMessages) ? $guild->bans->ban($this, [], $reason) : 
                   $guild->bans->ban($this, ['delete_message_days' => $daysToDeleteMessages], $reason);
    }