Newly joined guilds are not available to commands in their context
See original GitHub issueSummary
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
Issue Analytics
- State:
- Created 2 years ago
- Comments:25 (25 by maintainers)
Top Results From Across the Web
Can't create guild command · Issue #136
Summary I'm trying to create a guild command but it doesn't work. It worked before when I had all commands only being guild...
Read more >Python Discord 'Context' object has no attribute 'guild'
As M. I. Wright had wrote in their answer, you're using the async branch of discord.py. In the async branch, ctx.guild does not...
Read more >Registering slash commands
Slash commands can be registered in two ways; in one specific guild, or for every guild the bot is in. We're going to...
Read more >API Reference - discord.py - Read the Docs
A decorator that converts the provided method into a Command, adds it to the bot ... If the invite is for a guild...
Read more >Interactions API Reference - discord.py
If the interaction is not an application command related interaction or the command is not found in the client's attached tree then None...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Workaround:
Can validate. This revert/fix works.