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

chore: deprecate client options presence #10419

Merged
merged 6 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/discord.js/src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const Status = require('../util/Status');
const Sweepers = require('../util/Sweepers');

let deprecationEmittedForPremiumStickerPacks = false;
let deprecationEmittedForClientPresence = false;

/**
* The main hub for interacting with the Discord API, and the starting point for any bot.
Expand Down Expand Up @@ -139,7 +140,7 @@ class Client extends BaseClient {
* @private
* @type {ClientPresence}
*/
this.presence = new ClientPresence(this, this.options.presence);
this.presence = new ClientPresence(this, this.options.ws.presence ?? this.options.presence);

Object.defineProperty(this, 'token', { writable: true });
if (!this.token && 'DISCORD_TOKEN' in process.env) {
Expand Down Expand Up @@ -219,6 +220,15 @@ class Client extends BaseClient {
this.emit(Events.Debug, `Provided token: ${this._censoredToken}`);

if (this.options.presence) {
if (!deprecationEmittedForClientPresence) {
process.emitWarning(
'ClientOptions#presence is deprecated and will be removed. Use ClientOptions#ws#presence instead.',
'DeprecationWarning',
);

deprecationEmittedForClientPresence = true;
}

this.options.ws.presence = this.presence._parse(this.options.presence);
}

Expand Down Expand Up @@ -547,6 +557,9 @@ class Client extends BaseClient {
if (typeof options.ws !== 'object' || options.ws === null) {
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'ws', 'an object');
}
if (typeof options.ws.presence !== 'object' || options.ws.presence === null) {
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'ws.presence', 'an object');
}
if (typeof options.rest !== 'object' || options.rest === null) {
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'rest', 'an object');
}
Expand Down
1 change: 1 addition & 0 deletions packages/discord.js/src/util/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const { version } = require('../../package.json');
* only set this if you know what you are doing</warn>
* @property {BuildStrategyFunction} [buildStrategy] Builds the strategy to use for sharding
* @property {IdentifyThrottlerFunction} [buildIdentifyThrottler] Builds the identify throttler to use for sharding
* @property {PresenceData} [presence={}] Presence data to use upon login
*/

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ import {
APISelectMenuDefaultValue,
SelectMenuDefaultValueType,
InviteType,
GatewayPresenceUpdateData,
} from 'discord-api-types/v10';
import { ChildProcess } from 'node:child_process';
import { EventEmitter } from 'node:events';
Expand Down Expand Up @@ -5304,6 +5305,7 @@ export interface ClientOptions {
allowedMentions?: MessageMentionOptions;
partials?: readonly Partials[];
failIfNotExists?: boolean;
/** @deprecated Use {@link ClientOptions.ws.presence} instead */
presence?: PresenceData;
intents: BitFieldResolvable<GatewayIntentsString, number>;
waitGuildTimeout?: number;
Expand Down Expand Up @@ -6876,6 +6878,7 @@ export interface WebhookMessageCreateOptions extends Omit<MessageCreateOptions,
export interface WebSocketOptions {
large_threshold?: number;
version?: number;
presence?: GatewayPresenceUpdateData;
buildStrategy?(manager: WSWebSocketManager): IShardingStrategy;
buildIdentifyThrottler?(manager: WSWebSocketManager): Awaitable<IIdentifyThrottler>;
}
Expand Down
Loading