question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Command context's client Shard ID does not match guild's Shard ID

See original GitHub issue

Summary

When you compare the Shard ID of the client from a command context to the Shard ID of the client retrieved using the context’s Guild ID, they do not match.

Details

Running on 4.0.0-nightly-00833 packages across the board, .NET Core 3.1 on Windows 10 using Jetbrains Rider

Steps to reproduce

  1. Ensure your bot is in multiple guilds so that the bot can be accessed from multiple shards. I used 2 guilds.
  2. Inject the DiscordShardedClient into CommandsNext’s DI ServiceCollection so you may access it in the constructor of a command module
  3. Ensure the DiscordShardedClient is using more than one shard. For my test, I configured it to use 3 shards.
  4. Create a command module extending BaseCommandModule and insert the following command
    [Command("testshardmatch")]
    public async Task TestShardMatch(CommandContext ctx)
    {
        //Assuming the DiscordShardedClient has been DI'd into the module as _shardedClient
        await ctx.RespondAsync($"Context shard ID is {ctx.Client.ShardId} and by guild ID shard ID is {_shardedClient.GetShard(ctx.Guild.Id).ShardId}");
    }
    
  5. Execute this command for multiple guilds. You can find my examples in the notes. You should see that the IDs do not match

Notes

Guild A: image

Guild B: image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
alexhornercommented, Apr 11, 2021

Ah, I see. As I am not at 1k yet, I decided to manually shard so I may test sharding is working with my code prior to it happening automatically. Thanks for taking a look at this!

1reaction
alexhornercommented, Apr 11, 2021

@Neuheit The sharded client is injected like so:

private static DiscordShardedClient _discord;
private static IReadOnlyDictionary<int, CommandsNextExtension> _commands;
private static readonly ServiceCollection ServiceCollection = new ServiceCollection();

_discord = new DiscordShardedClient(new DiscordConfiguration
{
    Token = Configuration.Token,
    TokenType = TokenType.Bot,
    MinimumLogLevel = LogLevel.Debug,
    ShardCount = 3
});

ServiceCollection.AddSingleton(_discord);

_commands = await _discord.UseCommandsNextAsync(new CommandsNextConfiguration
{
    StringPrefixes = new List<string>
    {
        "!"
    },
    EnableMentionPrefix = true,
    Services = ServiceCollection.BuildServiceProvider(),
    IgnoreExtraArguments = true,
    EnableDefaultHelp = false
});

foreach (KeyValuePair<int,CommandsNextExtension> commandsNextExtension in _commands)
{
    commandsNextExtension.Value.RegisterCommands<TestShardMatchModule>();
}

await _discord.StartAsync();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Discord.js getting shards id - javascript
The error tells you that client.shards does not exist, that it is undefined . You cannot reference the property of that which does...
Read more >
API Reference
shard_id ( int ) – The shard ID that requested being IDENTIFY'd ... doesn't require Intents.members within a guild context, but due to...
Read more >
API Reference - nextcord
The default guild ids for every application command set. If the application command doesn't have any explicit guild ids set and this list...
Read more >
DescribeStream - Amazon Kinesis Data Streams Service
To process shards in chronological order, use the ID of the parent shard to track the lineage to the oldest shard. This operation...
Read more >
discord-hybrid-sharding
Example: A Discord bot with 4000 guilds Normally we would spawn 4 shards with the Sharding Manager ( ~4 x 300MB memory ),...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found