I'm trying to make some kind of abstraction where commands can be defined and will be registered as slash commands and text commands. I don't know if this already exists, so I thought I'd ask about it first. I made a basic attempt myself however the interfaces between the 2 types of commands are very different so I'm unsure if it's even possible in a way that's worth doing..
#Simple way to write commands that are both slash commands and text commands?
1 messages · Page 1 of 1 (latest)
The idea is something like
/test option1:some string option2:true option3:123
would also work like so:
!test -option1 some string -option2 true -option3 123
Assuming you wouldn't need access to the context, (you could pass in what you need)
you could separate the logic part of the command into an intermediary function that gets called by both the text & slash command.
so it could look something like this:
//slash module
[SlashCommand("test", "test command")]
public async Task TestCommand(string option1, bool option2, int option3)
=> Commands.TestCommandAsync(option1, option2, option3);
//text module
[Command("test")]
public async Task TestCommand(string option1, bool option2, int option3)
=> Commands.TestCommandAsync(option1, option2, option3);
//separate file
private static class Commands
{
public async Task TestCommandAsync(string param1, bool param2, int param3)
{
//do something
}
}
hm, maybe i can mess with source generators to generate the different variants for me
i think i would need access to context, tho
If the access to context is primarily for things like the Guild, Current User, Executing User, you could pass them into parameters that youd pass in
hm yeah, i wonder about returning a response though
text and slash commands have a different interface for that
you could make it return the response