Skip to content

🌐 Plugin Creation

Fran2019 edited this page May 27, 2024 · 17 revisions

AquΓ­ tienes los cΓ³digos convertidos en bloques de spoiler:

πŸ“ƒ 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: TestDescription
Example Template

For a full example template, refer to the BotMaster-TestPlugin repository.

By following this documentation, you can ensure that your plugin is correctly registered, starts properly, and handles commands efficiently.

Β‘Espero que esto sea lo que buscabas!

🧭 Navigation Menu

🏠 General

Clone this wiki locally