Skip to content

Commit

Permalink
bug: client not accepting intents in array form
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcole1340 committed Mar 6, 2021
1 parent c4e1dff commit 5fec86a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Discord/Discord.php
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,6 @@ protected function resolveOptions(array $options = []): array
'pmChannels' => false,
'storeMessages' => false,
'retrieveBans' => false,
'intents' => false,
'httpLogger' => new NullLogger(),
'intents' => Intents::getAllIntents(),
'socket_options' => [],
Expand All @@ -1317,7 +1316,7 @@ protected function resolveOptions(array $options = []): array
->setAllowedTypes('pmChannels', 'bool')
->setAllowedTypes('storeMessages', 'bool')
->setAllowedTypes('retrieveBans', 'bool')
->setAllowedTypes('intents', ['bool', 'array', 'int'])
->setAllowedTypes('intents', ['array', 'int'])
->setAllowedTypes('httpLogger', LoggerInterface::class);

$options = $resolver->resolve($options);
Expand All @@ -1330,6 +1329,21 @@ protected function resolveOptions(array $options = []): array
$options['logger'] = new NullLogger();
}

if (is_array($options['intents'])) {
$intent = 0;
$validIntents = Intents::getValidIntents();

foreach ($options['intents'] as $idx => $i) {
if (! in_array($i, $validIntents)) {
throw new IntentException('Given intent at index '.$idx.' is invalid.');
}

$intent |= $i;
}

$options['intents'] = $intent;
}

// Discord doesn't currently support IPv6
// This prevents xdebug from catching exceptions when trying to fetch IPv6
// for Discord
Expand Down

0 comments on commit 5fec86a

Please sign in to comment.