#Discord Slash Commands "Object Reference Not set to An Instance Of An Object"

1 messages · Page 1 of 1 (latest)

heavy pasture
#

Hello, I was experimenting with creating a bot that uses Dsharpplus slash commands, but I keep running into an issue when I attempt to run my command. I'm not too familiar with the syntax and everything behind this so I could very easily be doing something wrong, hopefully you can help.

trail ginkgo
#

is the first screenshot decompiled code? do you have "just my code" disabled in VS?

heavy pasture
#

Yeah I have just my code disabled, that is the SlashCommandsExtension.cs file, and is where it's breaking

trail ginkgo
#

turn it on and check the exception, maybe it's more descriptive

heavy pasture
#

Will-do!

#

For some reason now every time I input the command I just get "The application did not respond" in the text channel and no exception in VS

trail ginkgo
#

does it hit a breakpoint in the command method?

heavy pasture
#

Nope

trail ginkgo
#

hm weird. Your code looks fine to me. But I'm also no expert

heavy pasture
#

Hmmm yeah, I thought I was doing everything correctly, but it just would break every time -- weird

#

I appreciate your help, hopefully someone comes along that may know

dry tiger
#

Can we get a stack trace.

#

Furthermore, I suspect it's trying to inject a DiscordChannel into your class

#

Furthermore

#

You're injecting a client (The context has a client property anyway) but don't pass a service provider to the extension

heavy pasture
# dry tiger Can we get a stack trace.

System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=DSharpPlus.SlashCommands
StackTrace:
at DSharpPlus.SlashCommands.SlashCommandsExtension.CreateInstance(Type t, IServiceProvider services) in DSharpPlus.SlashCommands\SlashCommandsExtension.cs:line 571

heavy pasture
#

So would I need to have something like IServiceProvider Service passed into that function or something deeper than that?

dry tiger
#

No

heavy pasture
#

Yeah, I started searching through other projects, I think I may have found how to do it -- we'll see