Remove the need to register slash commands separately
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
We modified the slash command interface to allow getting command data, and created a generic implementation of it that automatically retrieves data from the command data. The interface should not be used now. Instead, extending the implementation is preferred as it provides a semi-working command already.
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package wtf.beatrice.hidekobot.objects;
|
||||
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface SlashCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* Get the command's registered label, or how Discord sees and runs the registered command.
|
||||
*
|
||||
@@ -12,6 +14,13 @@ public interface SlashCommand
|
||||
*/
|
||||
String getCommandName();
|
||||
|
||||
/**
|
||||
* Get a JDA command data object that will then be used to tell the Discord API the specifics of this
|
||||
* command.
|
||||
*
|
||||
* @return the command data object.
|
||||
*/
|
||||
CommandData getSlashCommandData();
|
||||
/**
|
||||
* Run the command logic by parsing the event and replying accordingly.
|
||||
*
|
||||
|
@@ -0,0 +1,24 @@
|
||||
package wtf.beatrice.hidekobot.objects;
|
||||
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SlashCommandImpl implements SlashCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return getSlashCommandData().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandData getSlashCommandData() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runSlashCommand(@NotNull SlashCommandInteractionEvent event) {
|
||||
event.reply("Base command implementation").queue();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user