BENBUN Coder
BENBUN Coder

Reputation: 4881

Discord.net SlashCommand error - Invalid context type

I am writing my first Discord bot heavily based on the example code published at https://github.com/discord-net/Discord.Net/tree/dev/samples/InteractionFramework

I am attempting to add a SlashCommand as per

        [SlashCommand("kavs", "This is a test.")]
        public async Task GreetUserAsync()
        {
            await RespondAsync(text: $"the command has worked", ephemeral: true);
        }

When the bot is running, the SlashCommand looks to have been registered as when I type a "/" I see the followingenter image description here

If I enter "/kavs" then I get the following error from the bot

enter image description here

On discord I see

enter image description here

Any ideas what I might be doing wrong?

Upvotes: 0

Views: 845

Answers (1)

Hervé
Hervé

Reputation: 1018

It's beacause the InteractionModuleBase class has an overload which requires a generic type.

I fixed the issue by replacing the module base class

: InteractionModuleBase<SocketInteractionContext<SocketSlashCommand>>

with

: InteractionModuleBase<SocketInteractionContext>

Upvotes: 2

Related Questions