Skip to content
This repository was archived by the owner on Dec 24, 2021. It is now read-only.

Commit 198d760

Browse files
authored
fix send shard.broadcastEval in discord v12 (#332)
1 parent c7a30b2 commit 198d760

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

src/commands/commands/load.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ module.exports = class LoadCommandCommand extends Command {
5151
if(this.client.shard) {
5252
try {
5353
await this.client.shard.broadcastEval(`
54-
if(this.shard.id !== ${this.client.shard.id}) {
54+
const ids = [${this.client.shard.ids.join(',')}];
55+
if(!this.shard.ids.some(id => ids.includes(id))) {
5556
const cmdPath = this.registry.resolveCommandPath('${command.groupID}', '${command.name}');
5657
delete require.cache[cmdPath];
5758
this.registry.registerCommand(require(cmdPath));

src/commands/commands/reload.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ module.exports = class ReloadCommandCommand extends Command {
3737
if(this.client.shard) {
3838
try {
3939
await this.client.shard.broadcastEval(`
40-
if(this.shard.id !== ${this.client.shard.id}) {
40+
const ids = [${this.client.shard.ids.join(',')}];
41+
if(!this.shard.ids.some(id => ids.includes(id))) {
4142
this.registry.${isCmd ? 'commands' : 'groups'}.get('${isCmd ? cmdOrGrp.name : cmdOrGrp.id}').reload();
4243
}
4344
`);

src/commands/commands/unload.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ module.exports = class UnloadCommandCommand extends Command {
3333
if(this.client.shard) {
3434
try {
3535
await this.client.shard.broadcastEval(`
36-
if(this.shard.id !== ${this.client.shard.id}) this.registry.commands.get('${args.command.name}').unload();
36+
const ids = [${this.client.shard.ids.join(',')}];
37+
if(!this.shard.ids.some(id => ids.includes(id))) {
38+
this.registry.commands.get('${args.command.name}').unload();
39+
}
3740
`);
3841
} catch(err) {
3942
this.client.emit('warn', `Error when broadcasting command unload to other shards`);

src/providers/sqlite-sync.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ class SyncSQLiteProvider extends SettingProvider {
224224
key = JSON.stringify(key);
225225
val = typeof val !== 'undefined' ? JSON.stringify(val) : 'undefined';
226226
this.client.shard.broadcastEval(`
227-
if(this.shard.id !== ${this.client.shard.id} && this.provider && this.provider.settings) {
227+
const ids = [${this.client.shard.ids.join(',')}];
228+
if(!this.shard.ids.some(id => ids.includes(id)) && this.provider && this.provider.settings) {
228229
let global = this.provider.settings.get('global');
229230
if(!global) {
230231
global = {};

src/providers/sqlite.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ class SQLiteProvider extends SettingProvider {
234234
key = JSON.stringify(key);
235235
val = typeof val !== 'undefined' ? JSON.stringify(val) : 'undefined';
236236
this.client.shard.broadcastEval(`
237-
if(this.shard.id !== ${this.client.shard.id} && this.provider && this.provider.settings) {
237+
const ids = [${this.client.shard.ids.join(',')}];
238+
if(!this.shard.ids.some(id => ids.includes(id)) && this.provider && this.provider.settings) {
238239
let global = this.provider.settings.get('global');
239240
if(!global) {
240241
global = {};

0 commit comments

Comments
 (0)