Repository navigation
Annotations
MrFrydae edited this page Sep 13, 2023
·
2 revisions
- On parameters to provide Discord with autocompletion values
- Must register completion values before they can be used
- On the Class itself to define the base commands for all sub commands defined
- On Subcommands to define aliases for the subcommand as root commands. Example if your command is
/foo barthen adding a@CommandAlias("fb")makes/fbthe same as/foo bar.
- Placed on a sub/command to restrict access
- Value of this command are elements of the Permission enum.
- Must be included on every parameter.
- Changes the display name of a parameter
- Must be included on every parameter and command method.
- Changes the description of a parameter or command
- Defines a subcommand on a Command class
- Can be added to a command
- Allowes for commands to be sent in DMs with the bot
This code creates a command /ping which replied with a hidden message.
Since it is a GlobalCommand, it can be sent in both a text channel, and a private message.
Note: Commands don't need parameters.
@CommandAlias("ping")
@Description("Pong!")
@GlobalCommand
public void onPing() {
replyHidden(":ping_pong: Pong!").queue();
}
This creates a command /mirror which duplicates a message into another channel.
This command requires the user to have the Manage Messages permission to execute it.
@CommandAlias("mirror")
@Description("Mirror a message into another channel")
@CommandPermission(Permission.MESSAGE_MANAGE)
public void onMirror(@Name("message") @Description("The ID of the message") String id,
@Name("channel") @Description("The channel you'd like to mirror to") TextChannel channel) {
getEvent().getInteraction().deferReply(true).queue(hook -> {
MessageChannel sentFrom = hook.getInteraction().getMessageChannel();
sentFrom.retrieveMessageById(id)
.onErrorFlatMap((error) -> hook.editOriginal(error.getMessage()))
.onSuccess((message) -> {
String contentRaw = message.getContentRaw();
channel.sendMessage(contentRaw).queue();
hook.editOriginal("Message mirrored").queue();
})
.queue();
});
}

