Java-Discord / JavaBot

General utility bot for the Discord Java Community
https://discordjug.net/
GNU General Public License v3.0
48 stars 22 forks source link
bot discord discord-bot java jda

JavaBot — General Utility Bot for the Discord Java Community

Banner

Usage

To start up, run the bot once, and it will generate a config directory. Stop the bot, and set the up all the following values:

NOTE: Don't forget to enable the Presence Intent, Server Members Intent and Message Content Intent on the Discord Developer Portal!

Note that this is just what is required for the bot to start. Certain features may require other values to be set.

Configuration

The bot's configuration consists of a collection of simple JSON files:

At startup, the bot will initially start by loading just the global settings, and then when the Discord ready event is received, the bot will add configuration for each guild it's in, loading it from the matching JSON file, or creating a new file if needed.

Commands

We're using DIH4JDA as our Command/Interaction framework, which makes it quite easy to add new commands.

PingCommand.java

/**
 * <h3>This class represents the /ping command.</h3>
 */
public class PingCommand extends SlashCommand {
    /**
     * The constructor of this class, which sets the corresponding {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData}.
     */
    public PingCommand() {
        setCommandData(Commands.slash("ping", "Shows the bot's gateway ping.")
                .setGuildOnly(true)
        );
    }

    @Override
    public void execute(@NotNull SlashCommandInteractionEvent event) {
        event.replyEmbeds(new EmbedBuilder()
                .setAuthor(event.getJDA().getGatewayPing() + "ms", null, event.getJDA().getSelfUser().getAvatarUrl())
                .setColor(Responses.Type.DEFAULT.getColor())
                .build()
        ).queue();
    }
}

For more information on how this works, visit the DIH4JDA Wiki!

API Documentation

GET guilds/{guild_id}/metrics

GET guilds/{guild_id}/users/{user_id}

GET guilds/{guild_id}/leaderboard/qotw?page=1

GET guilds/{guild_id}/leaderboard/experience?page=1

You can try out the API yourself on api.discordjug.net!

Credits

Inspiration we took from other communities: