Skip to content

Commit

Permalink
feat: add silent option to ShardingManager (#9506)
Browse files Browse the repository at this point in the history
* feat: add silent option to ShardingManager

* chore: update ShardingManagerOptions type

* chore: update typings

---------

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
  • Loading branch information
MovementGH and Jiralite committed Jul 7, 2023
1 parent 53c17e0 commit df40dcd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/discord.js/src/sharding/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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[]}
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions packages/discord.js/src/sharding/ShardingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,6 +54,7 @@ class ShardingManager extends EventEmitter {
totalShards: 'auto',
mode: 'process',
respawn: true,
silent: false,
shardArgs: [],
execArgv: [],
token: process.env.DISCORD_TOKEN,
Expand Down Expand Up @@ -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[]}
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 @@ -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<unknown>;
public eval<T>(fn: (client: Client) => T): Promise<T>;
Expand Down Expand Up @@ -2755,6 +2756,7 @@ export class ShardingManager extends EventEmitter {

public file: string;
public respawn: boolean;
public silent: boolean;
public shardArgs: string[];
public shards: Collection<number, Shard>;
public token: string | null;
Expand Down Expand Up @@ -6183,6 +6185,7 @@ export interface ShardingManagerOptions {
shardList?: number[] | 'auto';
mode?: ShardingManagerMode;
respawn?: boolean;
silent?: boolean;
shardArgs?: string[];
token?: string;
execArgv?: string[];
Expand Down

0 comments on commit df40dcd

Please sign in to comment.