Add initial Discord bot integration with JDA setup and environment token configuration

This commit is contained in:
akastijn 2025-08-23 23:17:51 +02:00
parent 42b11eecf1
commit 2e89fcec66
4 changed files with 67 additions and 1 deletions

26
discord/build.gradle.kts Normal file
View File

@ -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()
}

View File

@ -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);
}
}

View File

@ -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();
}
}

View File

@ -1,2 +1,2 @@
rootProject.name = "AltitudeWeb" rootProject.name = "AltitudeWeb"
include("open_api", "backend", "frontend", "database") include("open_api", "backend", "frontend", "database", "discord")