Files
MCbot_bryce/src/main/java/disMCbot.java
2024-04-09 11:39:35 +12:00

41 lines
1.4 KiB
Java

import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import javax.security.auth.login.LoginException;
public class disMCbot extends ListenerAdapter {
private TextChannel updateChannel; // Define the channel where updates will be posted
public static void main(String[] args) throws LoginException {
JDABuilder builder = JDABuilder.createDefault("YOUR_DISCORD_BOT_TOKEN");
builder.addEventListeners(new disMCbot());
builder.build();
}
@Override
public void onMessageReceived(MessageReceivedEvent event) {
if (event.getAuthor().isBot()) return; // Ignore messages from bots
String message = event.getMessage().getContentRaw();
// Check for conditions or events triggering updates
if (message.contains("Player1 died")) {
// Post update to the specified channel
if (updateChannel != null) {
updateChannel.sendMessage("Player1 has died in Minecraft!").queue();
}
} else if (message.contains("Player1 Exp")) {
// Post another type of update
if (updateChannel != null) {
updateChannel.sendMessage("Player1 gained experience in Minecraft!").queue();
}
}
}
public void setUpdateChannel(TextChannel channel) {
this.updateChannel = channel;
}
}