fix(ClientOptions): make ClientOptions#intents returns an IntentsBitField (#8617)

* fix(ClientOptions): make ClientOptions#intents returns an instance of IntentsBitField

* fix: client.options

* fix(types): Client#options

* fix(WebSocketShard): remove require for IntentsBitField

* fix(eslint): yarn format
This commit is contained in:
Idris
2022-10-09 22:05:50 +02:00
committed by GitHub
parent 5f72d8b645
commit 4c2955a5de
3 changed files with 4 additions and 5 deletions

View File

@@ -479,7 +479,7 @@ class Client extends BaseClient {
if (typeof options.intents === 'undefined') { if (typeof options.intents === 'undefined') {
throw new DiscordjsTypeError(ErrorCodes.ClientMissingIntents); throw new DiscordjsTypeError(ErrorCodes.ClientMissingIntents);
} else { } else {
options.intents = IntentsBitField.resolve(options.intents); options.intents = new IntentsBitField(options.intents).freeze();
} }
if (typeof options.shardCount !== 'number' || isNaN(options.shardCount) || options.shardCount < 1) { if (typeof options.shardCount !== 'number' || isNaN(options.shardCount) || options.shardCount < 1) {
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'shardCount', 'a number greater than or equal to 1'); throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'shardCount', 'a number greater than or equal to 1');

View File

@@ -5,7 +5,6 @@ const { setTimeout, setInterval, clearTimeout, clearInterval } = require('node:t
const { GatewayDispatchEvents, GatewayIntentBits, GatewayOpcodes } = require('discord-api-types/v10'); const { GatewayDispatchEvents, GatewayIntentBits, GatewayOpcodes } = require('discord-api-types/v10');
const WebSocket = require('../../WebSocket'); const WebSocket = require('../../WebSocket');
const Events = require('../../util/Events'); const Events = require('../../util/Events');
const IntentsBitField = require('../../util/IntentsBitField');
const Status = require('../../util/Status'); const Status = require('../../util/Status');
const WebSocketShardEvents = require('../../util/WebSocketShardEvents'); const WebSocketShardEvents = require('../../util/WebSocketShardEvents');
@@ -512,7 +511,7 @@ class WebSocketShard extends EventEmitter {
this.emit(WebSocketShardEvents.AllReady); this.emit(WebSocketShardEvents.AllReady);
return; return;
} }
const hasGuildsIntent = new IntentsBitField(this.manager.client.options.intents).has(GatewayIntentBits.Guilds); const hasGuildsIntent = this.manager.client.options.intents.has(GatewayIntentBits.Guilds);
// Step 2. Create a timeout that will mark the shard as ready if there are still unavailable guilds // Step 2. Create a timeout that will mark the shard as ready if there are still unavailable guilds
// * The timeout is 15 seconds by default // * The timeout is 15 seconds by default
// * This can be optionally changed in the client options via the `waitGuildTimeout` option // * This can be optionally changed in the client options via the `waitGuildTimeout` option
@@ -687,7 +686,7 @@ class WebSocketShard extends EventEmitter {
// Clone the identify payload and assign the token and shard info // Clone the identify payload and assign the token and shard info
const d = { const d = {
...client.options.ws, ...client.options.ws,
intents: IntentsBitField.resolve(client.options.intents), intents: client.options.intents.bitfield,
token: client.token, token: client.token,
shard: [this.id, Number(client.options.shardCount)], shard: [this.id, Number(client.options.shardCount)],
}; };

View File

@@ -768,7 +768,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
public channels: ChannelManager; public channels: ChannelManager;
public get emojis(): BaseGuildEmojiManager; public get emojis(): BaseGuildEmojiManager;
public guilds: GuildManager; public guilds: GuildManager;
public options: ClientOptions; public options: Omit<ClientOptions, 'intents'> & { intents: IntentsBitField };
public get readyAt(): If<Ready, Date>; public get readyAt(): If<Ready, Date>;
public readyTimestamp: If<Ready, number>; public readyTimestamp: If<Ready, number>;
public sweepers: Sweepers; public sweepers: Sweepers;