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.

DiscordClient throws when registering command with some overloads

See original GitHub issue

Summary

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

  1. Have a command overload similar to example

  2. Try to register it to the client

  3. Observe exception

  4. Change overloads to be explicit (4 instead of 2 with default value)

  5. 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:closed
  • Created 5 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
WamWooWamcommented, Feb 6, 2019

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

1reaction
WamWooWamcommented, Feb 6, 2019

Also are you using your discord client? Because you shouldn’t be doing that

Read more comments on GitHub >

github_iconTop 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 >

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