@@ -8,7 +8,7 @@ const { setTimeout: sleep } = require('node:timers/promises');
8
8
const { Collection } = require ( '@discordjs/collection' ) ;
9
9
const Shard = require ( './Shard' ) ;
10
10
const { DiscordjsError, DiscordjsTypeError, DiscordjsRangeError, ErrorCodes } = require ( '../errors' ) ;
11
- const { mergeDefault , fetchRecommendedShardCount } = require ( '../util/Util' ) ;
11
+ const { fetchRecommendedShardCount } = require ( '../util/Util' ) ;
12
12
13
13
/**
14
14
* This is a utility class that makes multi-process sharding of a bot an easy and painless experience.
@@ -47,20 +47,18 @@ class ShardingManager extends EventEmitter {
47
47
* @param {string } file Path to your shard script file
48
48
* @param {ShardingManagerOptions } [options] Options for the sharding manager
49
49
*/
50
- constructor ( file , options = { } ) {
50
+ constructor ( file , options ) {
51
51
super ( ) ;
52
- options = mergeDefault (
53
- {
54
- totalShards : 'auto' ,
55
- mode : 'process' ,
56
- respawn : true ,
57
- silent : false ,
58
- shardArgs : [ ] ,
59
- execArgv : [ ] ,
60
- token : process . env . DISCORD_TOKEN ,
61
- } ,
62
- options ,
63
- ) ;
52
+ const _options = {
53
+ totalShards : 'auto' ,
54
+ mode : 'process' ,
55
+ respawn : true ,
56
+ silent : false ,
57
+ shardArgs : [ ] ,
58
+ execArgv : [ ] ,
59
+ token : process . env . DISCORD_TOKEN ,
60
+ ...options ,
61
+ } ;
64
62
65
63
/**
66
64
* Path to the shard script file
@@ -76,7 +74,7 @@ class ShardingManager extends EventEmitter {
76
74
* List of shards this sharding manager spawns
77
75
* @type {string|number[] }
78
76
*/
79
- this . shardList = options . shardList ?? 'auto' ;
77
+ this . shardList = _options . shardList ?? 'auto' ;
80
78
if ( this . shardList !== 'auto' ) {
81
79
if ( ! Array . isArray ( this . shardList ) ) {
82
80
throw new DiscordjsTypeError ( ErrorCodes . ClientInvalidOption , 'shardList' , 'an array.' ) ;
@@ -98,7 +96,7 @@ class ShardingManager extends EventEmitter {
98
96
* Amount of shards that all sharding managers spawn in total
99
97
* @type {number }
100
98
*/
101
- this . totalShards = options . totalShards || 'auto' ;
99
+ this . totalShards = _options . totalShards || 'auto' ;
102
100
if ( this . totalShards !== 'auto' ) {
103
101
if ( typeof this . totalShards !== 'number' || isNaN ( this . totalShards ) ) {
104
102
throw new DiscordjsTypeError ( ErrorCodes . ClientInvalidOption , 'Amount of shards' , 'a number.' ) ;
@@ -115,7 +113,7 @@ class ShardingManager extends EventEmitter {
115
113
* Mode for shards to spawn with
116
114
* @type {ShardingManagerMode }
117
115
*/
118
- this . mode = options . mode ;
116
+ this . mode = _options . mode ;
119
117
if ( this . mode !== 'process' && this . mode !== 'worker' ) {
120
118
throw new DiscordjsRangeError ( ErrorCodes . ClientInvalidOption , 'Sharding mode' , '"process" or "worker"' ) ;
121
119
}
@@ -124,31 +122,31 @@ class ShardingManager extends EventEmitter {
124
122
* Whether shards should automatically respawn upon exiting
125
123
* @type {boolean }
126
124
*/
127
- this . respawn = options . respawn ;
125
+ this . respawn = _options . respawn ;
128
126
129
127
/**
130
128
* Whether to pass the silent flag to child process (only when {@link ShardingManager#mode} is `process`)
131
129
* @type {boolean }
132
130
*/
133
- this . silent = options . silent ;
131
+ this . silent = _options . silent ;
134
132
135
133
/**
136
134
* An array of arguments to pass to shards (only when {@link ShardingManager#mode} is `process`)
137
135
* @type {string[] }
138
136
*/
139
- this . shardArgs = options . shardArgs ;
137
+ this . shardArgs = _options . shardArgs ;
140
138
141
139
/**
142
140
* An array of arguments to pass to the executable (only when {@link ShardingManager#mode} is `process`)
143
141
* @type {string[] }
144
142
*/
145
- this . execArgv = options . execArgv ;
143
+ this . execArgv = _options . execArgv ;
146
144
147
145
/**
148
146
* Token to use for obtaining the automatic shard count, and passing to shards
149
147
* @type {?string }
150
148
*/
151
- this . token = options . token ?. replace ( / ^ B o t \s * / i, '' ) ?? null ;
149
+ this . token = _options . token ?. replace ( / ^ B o t \s * / i, '' ) ?? null ;
152
150
153
151
/**
154
152
* A collection of shards that this manager has spawned
0 commit comments