Skip to content

Conversation

@MattIPv4
Copy link
Contributor

@MattIPv4 MattIPv4 commented Nov 8, 2020

Please describe the changes this PR makes and why it should be merged:

Adds the ability to call broadcastEval and fetchClientValues from a shard to run on different target shard, instead of broadcasting to all and using an if in the given script to filter by shard.

Now you can target a shard directly:

const { ShardClientUtil } = require('discord.js');
const guild = '433980600391696384';

// Get the shard Id -- `client.shard.constructor.shardIdForGuildId` could also be used
const shard = ShardClientUtil.shardIdForGuildId(guild, 2);

// Get the guild from that shard only
const name = await client.shard.broadcastEval(`this.guilds.cache.get('${guild}').name`, shard);

return [name, shard, client.shardId];

We get back [JetBrains Community, 1, 0], so we can see it correctly went to the target shard and found the guild there.

Status

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

Semantic versioning classification:

  • This PR changes the library's interface (methods or parameters added)
    • This PR includes breaking changes (methods removed or renamed, parameters moved or removed)
  • This PR only includes non-code changes, like changes to documentation, README, etc.

@MattIPv4 MattIPv4 changed the title feat(Shard): support shard argument in broadcastEval feat(Shard): support shard argument in broadcastEval/fetchClientValues Nov 8, 2020
@MattIPv4 MattIPv4 marked this pull request as ready for review November 8, 2020 14:41
Copy link
Contributor

@jonahsnider jonahsnider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code probably works but I have a few minor suggestions with the shardIdForGuildId function.

Copy link
Contributor

@jonahsnider jonahsnider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New edits look good.

@MattIPv4 MattIPv4 changed the title feat(Shard): support shard argument in broadcastEval/fetchClientValues feat(Shard): shard-specific broadcastEval/fetchClientValues + shard Id util Nov 8, 2020
@MattIPv4 MattIPv4 requested a review from kyranet November 8, 2020 21:17
Copy link
Member

@SpaceEEC SpaceEEC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM

@MattIPv4 MattIPv4 requested a review from Gawdl3y November 18, 2020 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants