Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.
Joshua edited this page Jun 11, 2023 · 2 revisions

Overview

General Usage

To create a new RJA Instance, you can use the RJABuilder.

RJABuilder builder = new RJABuilder("token"); // Replace "token" with your bot token
// do some stuff
RJA rja = builder.build();

This creates a new RJA Instance, which you can use to do stuff as your bot.

You can also modify some things before building the instance:

RJABuilder builder = ...
        
builder.setStatus("Test Status", UserStatus.Presence.FOCUS); // Sets the Status of the Bot to "Test Status" with "FOCUS" as presence type.
builder.doCleanStatus(true); // Resets the status of the Bot if it does not get changed at startup. It is default true. If false, the status of the bot stays as before.
        
builder.registerEventListener(new MyEventListener()); // Registers a new EventListener. More about EventListeners at #EventListeners or in the JavaDocs
        
builder.disableCaching(CachingPolicy.MEMBER); // Disables caching for the Member Cache. Every CachePolicy is enabled by default.
// More about Caching at #Caching or in the JavaDocs

But wait, there is more. After building your RJA instance you can request stuff from the API.

RJA rja = ...

User user = rja.retrieveUser("01GXTJK9Q1JZVR1NZ32CGDCDKN").complete();  // Retrieves a User by its ID.

Message message = rja.retrieveMessage("channelId", "messageId").complete(); // Retrieves a Message by the channel id and the message id.
   

RestActions

These methods usually make use of the RestAction class. RestActions are used to fetch and handle data async. To get the data, you can use the complete() method, which can block the current thread until the data is fetched. If you want to handle the data async, you can use the queue() method, which takes a Consumer<T> as parameter. The queue() method can also be called without any parameters or with two parameters, which are a Consumer<T> and a Consumer<Throwable>. #queue() will add the RestAction to a queue and will execute it as soon as possible. This may take some time.

RJA rja = builder.build();

// One Consumer, only for the user
rja.retrieveUser("userId").queue(user -> {
    // do stuff with the user
});

// Two Consumers, one for the user and one for the exception
rja.retrieveUser("userId").queue(user -> {
    // do stuff with the user
}, throwable -> {
    // handle the exception
});

// Get the user sync
User user = rja.retrieveUser("userId").complete();

Sending Messages

You can send Messages to every GenericChannel using GenericChannel#sendMessage or GenericChannel#sendEmbeds. Both of this Methods return a MessageAction which can be used to modify the message before sending it.
To send a private Message to a User, you can use User#openPrivateChannel to retrieve a RestAction with the DirectChannel of the User. To send messages to this DirectChannel, you can use the same methods as with GenericChannel.

Clone this wiki locally