DiscordUtils is hosted on a custom repository at https://maven.mineking.dev. Replace VERSION with the lastest version (without the v
prefix).
Alternatively, you can download the artifacts from jitpack (not recommended).
repositories {
maven { url "https://maven.mineking.dev/releases" }
}
dependencies {
implementation "de.mineking:DiscordUtils:VERSION"
}
<repositories>
<repository>
<id>mineking</id>
<url>https://maven.mineking.dev/releases</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>de.mineking</groupId>
<artifactId>DiscordUtils</artifactId>
<version>VERSION</version>
</dependency>
</dependencies>
DiscordUtils requires JDA, so you have to have it in your bot's dependency list as well (You should already have it). Some managers might require other dependencies, that you have to add to your project in order for that manager to work. These additional dependencies are mentioned in the section of the corresponding manager.
To start using DiscordUtils you can simply create an instance of DiscordUtils
with the first constructor parameter being your JDA
instance and the second one your bot class instance.
Example:
public class TestBot {
public static void main(String[] args) {
new TestBot(args[0]);
}
public final JDA jda;
public final DiscordUtils discordUtils;
public TestBot(String token) {
jda = JDABuilder.createDefault(token)
.build();
discordUtils = DiscordUtils.create(jda, this)
.build();
}
}
You can then later access your bot instance from any place where DiscordUtils gives you access to the DiscordUtils
instance, which helps to avoid static abuse.
You can enable localization by calling the setLocalizationManager
method on your DiscordUtils
instance.
You can provide a default locale that will be set as default value and a set of locales that you support.
The third parameter is a LocalizationFunction
that you can use to provide a localized description for a localization path.
You can also change how the paths are generated automatically.
Sometimes, you might want to mirror your bot's console to your admins' direct messages or a text channel. DiscordUtils provides a simple way to archive this.
public class TestBot {
public static void main(String[] args) {
new TestBot(args[0]);
}
public final JDA jda;
public final DiscordUtils discordUtils;
public TestBot(String token) {
jda = JDABuilder.createDefault(token)
.build();
discordUtils = DiscordUtils.create(jda, this)
.mirrorConsole(RedirectTarget.directMessage(YOUR_USER_ID)) //Mirror the console to you dms
.build();
}
}