Sitelet https://github.com/Java-Discord/JavaBot/commit/1cbb58121ff07b6c47fad79c697f2eae14d99d3c
Skip to content

Commit 1cbb581

Browse files
Updated README.md
1 parent 78483dc commit 1cbb581

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Commands are defined in this bot using a `.yaml` configuration file located in `
2121

2222
These commands are then used by `net.javadiscord.javabot.command.InteractionHandler#registerSlashCommands(Guild)` to register the defined commands as Discord slash commands which become available to users in guilds and private messages with the bot.
2323

24-
**Each command MUST define a `handler` property, whose name is the fully-qualified class name of a `ISlashCommand`.** When registering commands, the bot will look for such a class, and attempt to create a new instance of it using a no-args constructor. Therefore, make sure that your handler class has a no-args constructor.
24+
**Each command MUST define a `handler` property, whose name is the fully-qualified class name of a `SlashCommand`.** When registering commands, the bot will look for such a class, and attempt to create a new instance of it using a no-args constructor. Therefore, make sure that your handler class has a no-args constructor.
2525

2626
### Privileges
2727
To specify that a command should only be allowed to be executed by certain people, you can specify a list of privileges. For example:
@@ -38,7 +38,38 @@ To specify that a command should only be allowed to be executed by certain peopl
3838
```
3939
In this example, we define that the `jam-admin` command is first of all, *not enabled by default*, and also we say that anyone from the `jam.adminRoleId` role (as found using `Bot.config.getJam().getAdminRoleId()`). Additionally, we also say that the user whose id is `235439851263098880` is allowed to use this command. See `BotConfig#resolve(String)` for more information about how role names are resolved at runtime.
4040

41-
*Context-Commands work in almost the same way, follow the steps above but replace `ISlashCommand` with `IMessageContextCommand` or `IUserContextCommand`.*
41+
*Context-Commands work in almost the same way, follow the steps above but replace `SlashCommand` with `MessageContextCommand` or `UserContextCommand`.*
42+
43+
### Autocomplete
44+
To enable Autocomplete for a certain Slash Command Option, head to the command's entry in the corresponding
45+
YAML-File and set the `autocomplete` value.
46+
47+
```yaml
48+
- name: remove
49+
description: Removes a question from the queue.
50+
options:
51+
- name: id
52+
description: The id of the question to remove.
53+
required: true
54+
autocomplete: true
55+
type: INTEGER
56+
```
57+
58+
Now, you just need to implement `Autocompletable` in your handler class.
59+
60+
```java
61+
@Override
62+
public AutoCompleteCallbackAction handleAutocomplete(CommandAutoCompleteInteractionEvent event) {
63+
return switch (event.getSubcommandName()) {
64+
case "remove" -> ListQuestionsSubcommand.replyQuestions(event);
65+
default -> event.replyChoices();
66+
};
67+
}
68+
```
69+
70+
The `handleAutocomplete` method of your handler class now gets fired once someone is focusing any Slash Command Option that has the `autocomplete`
71+
property set to true.
72+
4273

4374
# Configuration
4475
The bot's configuration consists of a collection of simple JSON files:

0 commit comments

Comments
 (0)