Add initial Discord bot integration with JDA setup and environment token configuration
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
plugins {
|
||||
id("java")
|
||||
}
|
||||
|
||||
group = "com.alttd.webinterface"
|
||||
version = "unspecified"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation(platform("org.junit:junit-bom:5.10.0"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
// JDA
|
||||
implementation("net.dv8tion:JDA:6.0.0-rc.2") {
|
||||
exclude("opus-java") // exclude audio
|
||||
exclude("tink") // exclude audio
|
||||
}
|
||||
compileOnly("org.projectlombok:lombok:1.18.38")
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.38")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.alttd.webinterface;
|
||||
|
||||
import com.alttd.webinterface.bot.DiscordBotInstance;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class DiscordBot {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String discordToken = System.getProperty("DISCORD_TOKEN");
|
||||
if (discordToken == null) {
|
||||
log.error("Discord token not found, put it in the DISCORD_TOKEN environment variable");
|
||||
System.exit(1);
|
||||
}
|
||||
DiscordBotInstance discordBotInstance = new DiscordBotInstance();
|
||||
discordBotInstance.start(discordToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.alttd.webinterface.bot;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||
|
||||
public class DiscordBotInstance {
|
||||
|
||||
@Getter
|
||||
private JDA jda;
|
||||
|
||||
public void start(String token) {
|
||||
jda = JDABuilder.createDefault(token,
|
||||
GatewayIntent.GUILD_MEMBERS,
|
||||
GatewayIntent.GUILD_PRESENCES,
|
||||
GatewayIntent.GUILD_MESSAGES,
|
||||
GatewayIntent.MESSAGE_CONTENT)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user