Newly joined guilds are not available to commands in their context
Created by: alexhorner
Summary
System.NullReferenceException
occurs when accessing ctx.Guild
properties when a command is executed, but only when the bot has joined the guild in which the command was run after startup.
Details
When a bot is started, and a command is run, ctx.Guild
can be accessed as expected, but only when the command is called from a guild which the bot was already in prior to starting up.
If the same command is called from a guild which the bot was joined to after it had started up, ctx.Guild
will be null.
Steps to reproduce
- Create a bot
- Join it to a guild
- Start it up
- Run the provided Guild command in the guild. It succeeds.
- Join it to another guild whilst it is running
- Run the provided Guild command in the new guild. It throws.
- Restart the bot
- Run the provided Guild command in the new guild again. It succeeds.
Notes
This issue affects DiscordClient, DiscordShardedClient with 1 shard and DiscordShardedClient with 3 shards.
Here is the provided Guild command:
[Command("guild")]
public async Task Guild(CommandContext ctx)
{
await ctx.RespondAsync($"You are calling from guild {ctx.Guild.Name} ({ctx.Guild.Id})");
}
I am using DSharpPlus 4.1.0-nightly-00915