Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 13 commits into from Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/discord.js/src/client/Client.js
Expand Up @@ -479,7 +479,7 @@ class Client extends BaseClient {
if (typeof options.intents === 'undefined') {
throw new TypeError(ErrorCodes.ClientMissingIntents);
} 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) {
throw new TypeError(ErrorCodes.ClientInvalidOption, 'shardCount', 'a number greater than or equal to 1');
Expand Down
5 changes: 2 additions & 3 deletions packages/discord.js/src/client/websocket/WebSocketShard.js
Expand Up @@ -5,7 +5,6 @@ const { setTimeout, setInterval, clearTimeout, clearInterval } = require('node:t
const { GatewayDispatchEvents, GatewayIntentBits, GatewayOpcodes } = require('discord-api-types/v10');
const WebSocket = require('../../WebSocket');
const Events = require('../../util/Events');
const IntentsBitField = require('../../util/IntentsBitField');
const Status = require('../../util/Status');
const WebSocketShardEvents = require('../../util/WebSocketShardEvents');

Expand Down Expand Up @@ -512,7 +511,7 @@ class WebSocketShard extends EventEmitter {
this.emit(WebSocketShardEvents.AllReady);
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
// * The timeout is 15 seconds by default
// * This can be optionally changed in the client options via the `waitGuildTimeout` option
Expand Down Expand Up @@ -687,7 +686,7 @@ class WebSocketShard extends EventEmitter {
// Clone the identify payload and assign the token and shard info
const d = {
...client.options.ws,
intents: IntentsBitField.resolve(client.options.intents),
intents: client.options.intents.bitfield,
token: client.token,
shard: [this.id, Number(client.options.shardCount)],
};
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/typings/index.d.ts
Expand Up @@ -765,7 +765,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
public channels: ChannelManager;
public get emojis(): BaseGuildEmojiManager;
public guilds: GuildManager;
public options: ClientOptions;
public options: Omit<ClientOptions, "intents"> & { intents: IntentsBitField };
public get readyAt(): If<Ready, Date>;
public readyTimestamp: If<Ready, number>;
public sweepers: Sweepers;
Expand Down