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

feat: add silent option to ShardingManager #9506

Merged
merged 4 commits into from
Jul 7, 2023
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
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