Added some Documentation for Mobot: Introduction, Installation, Getting Started on Custom modules, Lifecycle Methods and SlashCommands

This commit is contained in:
sieadev
2025-04-21 16:22:40 +02:00
parent 6c929163f8
commit 300afed700
13 changed files with 417 additions and 5 deletions
+46
View File
@@ -0,0 +1,46 @@
---
banner_title: "MoBot - Command Arguments"
banner_description: "Learn how to use command arguments in MoBot"
---
# 🛠️ Command Arguments
Command arguments allow you to pass additional information to your commands when they are invoked. This is useful for creating dynamic commands that can perform different actions based on user input.
## 📜 `@SlashCommandArgument` Annotation
The `@SlashCommandArgument` annotation is used to define an argument for a slash command. You can specify the name, description, type, and whether the argument is required or optional.
You can add it to the method that handles the command, and it will automatically parse the argument from the command invocation.
`SlashCommandArgument`'s can also be stacked, so you can have multiple arguments for a single command.
Optionally you can add a `Map<String, Object>` to the method signature to get all arguments as a Map. If you prefer to retrieve the arguments from the event, you can use `#event.getOptions()`.
| Option | Description |
|-----------------|-----------------------------------------------------------------------------|
| `name` | The name of the argument. This is what users will type to provide the value. |
| `description` | A short description of what the argument does. |
| `type` | The type of the argument. This can be a string, integer, etc. |
| `required` | Whether the argument is required or optional. |
| `autoComplete` | Whether the argument should be auto-completed. |
Heres an example of a command with an argument using the `@SlashCommandArgument` annotation:
```java
public class MyCommand implements SlashCommandHandler {
@SlashCommand(
name = "greet",
description = "Greet a user"
)
@SlashCommandArgument(
name = "user",
description = "The user to greet",
type = OptionType.USER,
required = true
)
public void onGreetCommand(SlashCommandInteractionEvent event, Map<String, Object> args) {
// Get the user argument
User user = (User) args.get("user");
// Reply to the command
event.reply("Hello, " + user.getName() + "!").queue();
}
}
```
+59
View File
@@ -0,0 +1,59 @@
---
banner_title: "MoBot - Creating a Command"
banner_description: "Learn how to create custom commands for MoBot"
---
# 🛠️ Creating a Command
Commands are a core feature of Discord Bots. They allow users to interact with the bot and perform various actions. In MoBot, creating a command is straightforward and flexible, allowing you to define custom behavior for your bot.
## 🚀 Commands in the MoBot API
To make commands easy to use, MoBot provides a extensive API for creating and managing commands.
Apart from the `SlashCommandHandler` interface, the SlashCommand System is build entirely from annotations.
::: warning NOTE
You will have to implement the `SlashCommandHandler` interface if you want to use `@SlashCommand` and other annotations.
:::
## 📜 `@SlashCommand` Annotation
The `@SlashCommand` annotation is used to define a slash command. Apart from the name and description, you can also specify aliases and required permissions.
This annotation is placed on a method that will handle the command when it is invoked.
The method should accept a `SlashCommandInteractionEvent` parameter, which contains information about the command invocation and allows you to respond to the user.
| Option | Description |
|-----------------|------------------------------------------------------------------------------|
| `name` | The name of the command. This is what users will type to invoke the command. |
| `description` | A short description of what the command does. |
| `aliases` | An array of alternative names for the command. |
| `permissions` | The permission required to use the command. |
Heres an example of a simple `PingCommand` using the `@SlashCommand` annotation:
```java
public class PingCommand implements SlashCommandHandler {
@SlashCommand(
name = "ping",
description = "Ping the bot to check if it's alive"
)
public void onPingCommand(SlashCommandInteractionEvent event) {
event.reply("Pong!").queue();
}
}
```
## 🛠️ Registering the Command
To register the command, you need to create an instance of your command class and register it using the `#registerSlashCommandHandler` method in your module's main class.
Here's an example of how to register the `PingCommand` in your module:
```java
public class MyModule extends MbModule {
@Override
public void onEnable() {
registerSlashCommandHandler(new PingCommand());
}
}
```