Discord API - a unified set of tools for working with the Discord API from other plugins
- Install AvrixLoader
- Download the plugin from the releases page
- Move to the
plugins
folder - Start the server and shut down
- Configure the plugin in the plugin settings folder
plugins/discord-api
- Download and include the library as
compileOnly
- In the right place in the plugin (preferably in the main class) get the API object:
DiscordAPI discordAPI = ServiceManager.getService(DiscordAPI.class);
To add a command, you need to create a new command class by extending Command
from the Discord API package:
/**
* Example command
*/
public class ExampleCommand extends Command {
/**
* Team constructor. Arguments: command name, description
*/
public ExampleCommand() {
super("example", "Example description");
}
/**
* Executes the command with the given arguments.
*
* @param event The MessageCreateEvent triggering the command execution.
* @param args The arguments passed to the command.
* @return {@code true} if the command execution was successful, {@code false} otherwise.
*/
@Override
public boolean execute(MessageCreateEvent event, String[] args) {
return true;
}
}
When initializing the plugin, add the command to the DiscordAPI registry:
CommandsManager.addCommand(new ExampleCommand());
OnDiscordCommand
-> Triggered when a chat command arrivesOnDiscordMessage
-> Triggered when a chat message arrives
/**
* Retrieves the GatewayDiscordClient instance.
*
* @return the GatewayDiscordClient instance used for managing the gateway connection.
*/
GatewayDiscordClient getGateway();
/**
* Retrieves the DiscordClient instance.
*
* @return the DiscordClient instance used for REST API interactions.
*/
DiscordClient getClient();
/**
* Send a message to a specified channel.
*
* @param channelId ID of the channel where to send the message
* @param message Message to send
*/
void sendMessage(String channelId, String message);
/**
* Send an embed message to a specified channel.
*
* @param channelId ID of the channel where to send the embed
* @param embedCreateSpec The embed to send
*/
void sendEmbedMessage(String channelId, EmbedCreateSpec embedCreateSpec);
/**
* Send a message to a specified webhook.
*
* @param webhookUrl The URL of the webhook
* @param webhookExecuteSpec The WebhookExecuteSpec containing the message or embed to send
*/
void sendWebhook(String webhookUrl, WebhookExecuteSpec webhookExecuteSpec);
/**
* Deletes a message in a specified channel.
*
* @param channelId the ID of the channel where the message is located
* @param messageId the ID of the message to be deleted
*/
void deleteMessage(String channelId, String messageId);
/**
* Edits a message in a specified channel.
*
* @param channelId the ID of the channel where the message is located
* @param messageId the ID of the message to be edited
* @param messageEditSpec the MessageEditSpec containing the new content or embed for the message
*/
void editMessage(String channelId, String messageId, MessageEditSpec messageEditSpec);
/**
* Gets information about a user by ID.
*
* @param userId the ID of the user to retrieve
* @return a Mono emitting the User object
*/
Mono<User> getUserById(String userId);
/**
* Gets information about a channel by ID.
*
* @param channelId the ID of the channel to retrieve
* @return a Mono emitting the Channel object
*/
Mono<Channel> getChannelById(String channelId);
/**
* Adds a reaction to a specified message.
*
* @param channelId the ID of the channel where the message is located
* @param messageId the ID of the message to add a reaction to
* @param emoji the emoji to react with
*/
void addReaction(String channelId, String messageId, String emoji);
/**
* Removes a reaction from a specified message.
*
* @param channelId the ID of the channel where the message is located
* @param messageId the ID of the message to remove a reaction from
* @param userId the ID user
* @param emoji the emoji to remove
*/
void removeReaction(String channelId, String messageId, String userId, String emoji);
/**
* Removes a reaction from a specified message.
*
* @param channelId the ID of the channel where the message is located
* @param messageId the ID of the message to remove a reaction from
* @param emoji the emoji to remove
*/
void removeReaction(String channelId, String messageId, String emoji);
This software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement of third party rights. Neither the author of the software nor its contributors shall be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.
By using this software, you agree to these terms and release the author of the software and its contributors from any liability associated with the use of this software.
This project is licensed under MIT License.