Not everything is working at the moment. Ask on the discord-botlist.eu Server if you have any questions
DblEu-java is the official Java library of discord-botlist.eu
- Creating the DblEu-Object
- Listening to events
- Post data
- Fetching votes
- Working with RatelimitManagers
- Simulate Events
- Catch votes with webhooks
- API Key and ID
- License
To use the library, you must create the DblEu.Builder()
object first.
The API requires an API Key and an id
See API Key and ID
Example
DblEu api = new DblEu.Builder()
.setAPIKey("key") //Set the API Keys
.setId("id") //Set the client id
.build(); //Build the object
You can catch events to work even better with the API
Example
public class DblEuEvents extends DblEuListerns { //Extend all event listeners from the DblEuListerns class
//Ready event
@Override
public void onReady(ReadyEvent event) {
System.out.println("Version of Library: " + event.getDblEu().version()); //Printing the Library-Version
}
}
You can catch multiple events in one class
Example
public class DblEuEvents extends DblEuListerns { //Extend all event listeners from the DblEuListerns class
//Ready event
@Override
public void onReady(ReadyEvent event) {
System.out.println("Version of Library: " + event.getDblEu().version()); //Printing the Library-Version
}
//Vote event
@Override
public void onVote(VoteEvent event) {
System.out.println("Received a vote from " + event.getVote().getVoter().getName() + " (" + event.getVote().getVoter().getId() + ")"); //Printing information
}
}
Note
You need to register all of these listeners before you build the DblEu
object.
Example
DblEu api = new DblEu.Builder()
.setAPIKey("key") //Set the API Keys
.setId("id") //Set the client id
.addEventListener(new DblEuEvents()) //Add an event listener
.build(); //Build the object
You can post data which will be shown on your bots page.
DblEu api = ...;
PostData postData = new DataBuilder()
.setServers(servers)
.build();
api.postData(postData).queue((consumer) -> {
System.out.println("Sent data");
});
You can also fetch all current votes
Example
public static void printVotes(DblEu api) {
api.fetchVotes().queue((votes) -> {
System.out.println("All votes:");
for(Vote v : votes) System.out.println(" - by "+v.getVoter().getName()+" at "+v.getTime());
if(votes.size() == 0) System.out.println("There are no votes");
},
(e) -> e.printStackTrace());
}
You can work with a RatelimtManager to prevent temporary bans
@Override
public void onReady(ReadyEvent event) {
int servers = 0;
DataBuilder dataBuilder = new DataBuilder()
.setServers(servers);
try {
event.getDblEu().postData(dataBuilder.build()).queue((consumer) -> {
System.out.println("Sent data");
});
} catch(RatelimitReachedException ex) {
System.out.println("Could not send data");
}
}
@Override
public void onReady(ReadyEvent event) {
int servers = 0;
PostData postData = new DataBuilder()
.setServers(servers)
.build();
event.getDblEu().postData(postData).queue((consumer) -> {
System.out.println("Sent data");
},
(throwable) -> {
System.out.println("Could not send data");
});
}
@Override
public void onReady(ReadyEvent event) {
RatelimitManager manager = event.getDblEu().getRatelimitManager();
if(manager.postData().getAvailableRequests() != 0) event.getDblEu().postData(
new DataBuilder()
.setServers(0)
.build()
).queue((consumer) -> {
System.out.println("Sent data");
}); else System.out.println("Could not send data");
}
You can simulate events to test features etc.
Example
api.simulateEvent(ReadyEvent.class, api.getSimulationBuilder().build()).queue((event) -> {
System.out.println("Version of simulated ready event: "+event.getDblEu().version());
})
Check the Javadoc, examples, wiki or ask on the Discord Server if you don't know which methods you need to use at the builder.
You need to catch the votes of your bot with webhooks. We show you how you can receive these
If you want to catch votes with our webhook implementation, you need to follow these steps:
- Go to dev.discord-botlist.eu and login with you discord account.
- Click on your bot
- Scroll down to "Webhook-URL" and paste the following:
<ip>:2526/webhook
- Note: You need to replace
<ip>
with your IP-Address
- Note: You need to replace
- Add
.enableWebhooks(true)
to the builder- Example
DblEu api = new DblEu.Builder() .setAPIKey("key") //Setting the API Keys .setId("id") //Setting the client id .enableWebhooks(true) //enable webhooks .build(); //Build the object
- Example
You can change the url for the webhook with .setWebhookPath()
Example:
DblEu api = new DblEu.Builder()
.setAPIKey("key") //Setting the API Keys
.setId("id") //Setting the client id
.enableWebhooks(true) //enable webhooks
.setWebhookPath("/hook") //set webhook path
.build(); //Build the object
If you want to use your own webserver, you can simulate a VoteEvent
Example
DblEu api = ...;
String body = "...";
api.simulateEvent(VoteEvent.class, api.getSimulationBuilder().setBody(body).build()).queue((event) -> {
System.out.println("Received a vote from " + event.getVote().getVoter().getName() + " (" + event.getVote().getVoter().getId() + ")"); //Printing information
})
The API Key and the ID are required parameter of the library to tell the API who you are.
Follow these steps to get your bots API Key:
- Go to dev.discord-botlist.eu and login with you discord account.
- Click on your bot
- Scroll down to "API-Key" and click the "Copy"-Button
- Go to the discord developer portal and go to the setting of your bot.
- Copy the text under the "APPLICATION ID" headline or click the "Copy" button
This Library is licensed under the GNU General Public License v3.0