Top.gg Documentation

/

Java

Top.gg Java library


Java Library

The community-maintained Java library for Top.gg. If you experience any issues/bugs please submit an issue on Github.

Installation

Replace VERSION with the latest version or commit hash. The latest version can be found under releases.

Maven

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>org.discordbots</groupId>
        <artifactId>DBL-Java-Library</artifactId>
        <version>VERSION</version>
    </dependency>
</dependencies>

Gradle

repositories {
    maven { url 'https://jitpack.io' }
}
dependencies {
    compile 'org.discordbots:DBL-Java-Library:VERSION'
}

Usage

First, build a DiscordBotListAPI object.

DiscordBotListAPI api = new DiscordBotListAPI.Builder()
	.token("token")
	.botId("botId")
	.build();

Posting bot stats

Top.gg provides three ways to post your bots stats. #1 Post the server count for the whole bot.

int serverCount = ...; // the total amount of servers across all shards

api.setStats(serverCount);

#2 Post the server count for an individual shard

int shardId = ...; // the id of this shard
int shardCount = ...; // the amount of shards
int serverCount = ...; // the server count of this shard

api.setStats(shardId, shardCount, serverCount);

#3 Post the server counts for every shard within a single request.

List<Integer> shardServerCounts = ...; // a list of all the shards' server counts

api.setStats(shardServerCounts);

Checking votes

You can use this to tell if a user has voted for your bot before.

String userId = ...; // ID of the user you're checking
api.hasVoted(userId).whenComplete((hasVoted, e) -> {
	if(hasVoted)
		System.out.println("This person has voted!");
	else
		System.out.println("This person has not voted!");
});

Get vote multiplier

Use this to check if there is a vote multiplier applied at the moment.

api.getVotingMultiplier().whenComplete((multiplier, e) -> {
	if(multiplier.isWeekend())
		System.out.println("It's the weekend, so votes are worth 2x!");
	else
		System.out.println("It's not the weekend :pensive:");
});
Edit on GitHub