From df40dcdb850c398642ebc5cd6e4c48034280f464 Mon Sep 17 00:00:00 2001 From: MovementGH <48330137+MovementGH@users.noreply.github.com> Date: Fri, 7 Jul 2023 19:32:29 -0400 Subject: [PATCH] feat: add silent option to ShardingManager (#9506) * feat: add silent option to ShardingManager * chore: update ShardingManagerOptions type * chore: update typings --------- Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> --- packages/discord.js/src/sharding/Shard.js | 7 +++++++ packages/discord.js/src/sharding/ShardingManager.js | 9 +++++++++ packages/discord.js/typings/index.d.ts | 3 +++ 3 files changed, 19 insertions(+) diff --git a/packages/discord.js/src/sharding/Shard.js b/packages/discord.js/src/sharding/Shard.js index 0f4e81761409..f833309f9f06 100644 --- a/packages/discord.js/src/sharding/Shard.js +++ b/packages/discord.js/src/sharding/Shard.js @@ -42,6 +42,12 @@ class Shard extends EventEmitter { */ this.id = id; + /** + * Whether to pass silent flag to the shard's process (only when {@link ShardingManager#mode} is `process`) + * @type {boolean} + */ + this.silent = manager.silent; + /** * Arguments for the shard's process (only when {@link ShardingManager#mode} is `process`) * @type {string[]} @@ -124,6 +130,7 @@ class Shard extends EventEmitter { .fork(path.resolve(this.manager.file), this.args, { env: this.env, execArgv: this.execArgv, + silent: this.silent, }) .on('message', this._handleMessage.bind(this)) .on('exit', this._exitListener); diff --git a/packages/discord.js/src/sharding/ShardingManager.js b/packages/discord.js/src/sharding/ShardingManager.js index 0fcba7e19c9d..288456a13540 100644 --- a/packages/discord.js/src/sharding/ShardingManager.js +++ b/packages/discord.js/src/sharding/ShardingManager.js @@ -34,6 +34,8 @@ class ShardingManager extends EventEmitter { * @property {string|number[]} [shardList='auto'] List of shards to spawn or "auto" * @property {ShardingManagerMode} [mode='process'] Which mode to use for shards * @property {boolean} [respawn=true] Whether shards should automatically respawn upon exiting + * @property {boolean} [silent=false] Whether to pass the silent flag to child process + * (only available when mode is set to 'process') * @property {string[]} [shardArgs=[]] Arguments to pass to the shard script when spawning * (only available when mode is set to 'process') * @property {string[]} [execArgv=[]] Arguments to pass to the shard script executable when spawning @@ -52,6 +54,7 @@ class ShardingManager extends EventEmitter { totalShards: 'auto', mode: 'process', respawn: true, + silent: false, shardArgs: [], execArgv: [], token: process.env.DISCORD_TOKEN, @@ -123,6 +126,12 @@ class ShardingManager extends EventEmitter { */ this.respawn = options.respawn; + /** + * Whether to pass the silent flag to child process (only when {@link ShardingManager#mode} is `process`) + * @type {boolean} + */ + this.silent = options.silent; + /** * An array of arguments to pass to shards (only when {@link ShardingManager#mode} is `process`) * @type {string[]} diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 72104944a055..38faf58b70f5 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -2696,6 +2696,7 @@ export class Shard extends EventEmitter { public manager: ShardingManager; public process: ChildProcess | null; public ready: boolean; + public silent: boolean; public worker: Worker | null; public eval(script: string): Promise; public eval(fn: (client: Client) => T): Promise; @@ -2755,6 +2756,7 @@ export class ShardingManager extends EventEmitter { public file: string; public respawn: boolean; + public silent: boolean; public shardArgs: string[]; public shards: Collection; public token: string | null; @@ -6183,6 +6185,7 @@ export interface ShardingManagerOptions { shardList?: number[] | 'auto'; mode?: ShardingManagerMode; respawn?: boolean; + silent?: boolean; shardArgs?: string[]; token?: string; execArgv?: string[];