DiscordClient throws when registering command with some overloads
See original GitHub issueSummary
A NullReferenceException
occurs when trying to register a command with some overloads with default values, but works fine if you make overloads explicit.
Details
Using .net core 2.1 with DSharpPlus & CommandsNext nightly 4.0.0-nightly-00564.
Stacktrace:
System.NullReferenceException: Object reference not set to an instance of an object.
at DSharpPlus.DiscordClient.Dispose()
at CompatBot.Program.Main(String[] args) in C:\\Develop\\discord-bot\\CompatBot\\Program.cs:line 262
Line 262 is the end of the using
scope, it throws on registering the command inside said scope.
Example of a command overload:
class BadOverload
{
[Command("c")]
public async Task Crash(CommandContext ctx, int? year = null) => ;
[Command("c")]
public async Task Crash(CommandContext ctx, string name = null, int? year = null) => ;
}
Steps to reproduce
-
Have a command overload similar to example
-
Try to register it to the client
-
Observe exception
-
Change overloads to be explicit (4 instead of 2 with default value)
-
Observe no exceptions
Notes
Exception that is being thrown, is useless as it points to trying to dispose a null
client for some reason, instead of pointing to the issue with overload resolving.
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
v4.0
DiscordClient ::Dispose() throws NullReferenceException if no succesfull connection was established #554 opened by schaap
Read more >Is there a way to overload a SlashCommand?
Slash commands are registered with Discord. You can't register multiple commands with the same name. You'd either use multiple commands or a ...
Read more >Slash Commands | DSharpPlus
Slash commands can be registered either globally or for a certain guild. However, if you try to register them globally, they can take...
Read more >Discord4J Documentation
You'll only need 1 account registered at Discord. ... public static IDiscordClient getClient(String token) throws DiscordException<br />.
Read more >Discord Crasher
Commands : TO ADD THE BOT YOU MUST HAVE THE MANAGE SERVER PERMISSION. ... Method 4: Delete Discord Cache If some of Discord...
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
Don’t do that, dispose the client when you’re application exits, or alternatively don’t at all, in doing so you’re disconnecting the client, probably before it actually connects in the first place
Also are you
using
your discord client? Because you shouldn’t be doing that