-
Notifications
You must be signed in to change notification settings - Fork 1
🌐 Plugin Creation
Fran2019 edited this page May 27, 2024
·
17 revisions
Claro, aquí tienes los códigos como bloques de spoiler con un poco de espacio entre ellos:
📃 Main.java (i.fran2019.Test.Main)
package i.fran2019.Test;
import i.fran2019.BotMaster.API.implementations.Plugin;
import i.fran2019.BotMaster.BotMaster;
import i.fran2019.Test.Commands.TestCMD;
import lombok.Getter;
@Getter
public class Test extends Plugin {
// Reference to the current instance of the plugin
private final Test test = this;
// Constructor to initialize the plugin with its name and description
public Test(BotMaster botMaster, String name, String description) {
super(botMaster, name, description);
}
// Called when the plugin is enabled
@Override
public void onEnable() {
// Registering the command with the command manager
getBotMaster().getCommandManager().registerCommand(new TestCMD("test2" /* Command Name */));
// Logging that the plugin has been loaded
getLogger().info("Plugin Loaded");
}
// Called when the plugin is disabled
@Override
public void onDisable() {
// Logging that the plugin has been disabled
getLogger().info("Plugin Disabled");
}
}📃 TestCMD.java (i.fran2019.Test.Commands.TestCMD)
package i.fran2019.Test.Commands;
import i.fran2019.BotMaster.API.annotations.CommandOption;
import i.fran2019.BotMaster.API.implementations.Command;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionType;
public class TestCMD extends Command {
// Constructor to initialize the command with its name
public TestCMD(String name) {
super(name);
}
// Creating a new command option with predefined choices
@CommandOption(
name = "Option1",
description = "useless",
required = true,
type = OptionType.STRING,
choices = {"Test|test", "Test2|test2", "Test4"}
)
String option1;
// Logic to be executed when the command is run
@Override
public void onExecute(SlashCommandInteractionEvent e) {
// Sending a response message to the user
e.reply("Hello from the Test command! Output: " + option1).queue();
}
}📃 bot.yml (Resources Folder)
main: i.fran2019.Test.Test
name: TestPlugin
description: TestDescriptionExample Template
Para un ejemplo completo, consulta el repositorio BotMaster-TestPlugin.
Siguiendo esta documentación, puedes asegurarte de que tu plugin esté registrado correctamente, se inicie adecuadamente y maneje los comandos de manera eficiente.
¡Listo! ¿Hay algo más en lo que pueda ayudarte?
Support: Discord