using shading on the Jar
switched to Discord4j instead of JDA getEventDispatcher() not working NEW be04 version
This commit is contained in:
@@ -1,29 +1,39 @@
|
||||
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import discord4j.core.DiscordClient;
|
||||
import discord4j.core.DiscordClientBuilder;
|
||||
import discord4j.core.event.domain.lifecycle.ReadyEvent;
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||
import discord4j.core.object.presence.Activity;
|
||||
import discord4j.core.object.presence.Presence;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import listeners.MinecraftEventListener;
|
||||
|
||||
public class disMCbot {
|
||||
private static TextChannel updateChannel;
|
||||
private static final Logger logger = LogManager.getLogger(disMCbot.class);
|
||||
|
||||
public static void main(String[] args) throws LoginException {
|
||||
public static void main(String[] args) {
|
||||
logger.info("Starting Discord Bot...");
|
||||
String token = "MTIyNjY1NTgxODU0NDMxNjQxNw.GXAYvx.m2_ZmH-J5-iGhqdkW3M2VViG1wBQguKq-OjN80";
|
||||
JDABuilder builder = JDABuilder.createDefault(token);
|
||||
builder.addEventListeners(new MinecraftEventListener(updateChannel));
|
||||
builder.build();
|
||||
}
|
||||
|
||||
public void setUpdateChannel(TextChannel channel) {
|
||||
disMCbot.updateChannel = channel;
|
||||
}
|
||||
DiscordClient client = DiscordClientBuilder.create(token).build();
|
||||
client.login().block();
|
||||
|
||||
client.getEventDispatcher().on(ReadyEvent.class)
|
||||
.subscribe(ready -> {
|
||||
System.out.println("Logged in as: " + ready.getSelf().getUsername());
|
||||
client.updatePresence(Presence.online(Activity.playing("Minecraft")));
|
||||
});
|
||||
|
||||
client.getEventDispatcher().on(MessageCreateEvent.class)
|
||||
.subscribe(event -> {
|
||||
String messageContent = event.getMessage().getContent();
|
||||
if (messageContent.equalsIgnoreCase("!ping")) {
|
||||
event.getMessage().getChannel().block().createMessage("Pong!").block();
|
||||
}
|
||||
// Add more commands as needed
|
||||
});
|
||||
|
||||
client.onDisconnect().block();
|
||||
}
|
||||
// Other methods and event listeners can be added as needed
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user