Reputation: 51
I'm trying to do my first Discord JDA bot with Java. (most part of tutorials and questions here on StackOverflow that I've found used Javascript, so I think it should be mentioned).
I'm not managing to get any message that I send to #general channel. I did my code following this tutorial and tried to fix the issue with code from this link.
JDA version: 4.2.0_240 IntelliJ version: 2020.3.2 JDK 11.0.9 Java SE 8
My Main
class:
import com.neovisionaries.ws.client.WebSocket;
import com.neovisionaries.ws.client.WebSocketFactory;
import net.dv8tion.jda.api.AccountType;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import javax.security.auth.login.LoginException;
import java.io.IOException;
import java.util.Objects;
public class Main extends ListenerAdapter {
public static void main(String[] args) throws LoginException, IOException {
JDABuilder builder = new JDABuilder(AccountType.BOT);
String token = "my_token";
WebSocketFactory factory = new WebSocketFactory();
WebSocket ws = factory.createSocket("ws://discord.com/channels/817842449882939392/817842449882939396", 30000);
builder.setToken(token);
builder.addEventListeners(new Main());
builder.build();
}
@Override
public void onMessageReceived(MessageReceivedEvent event){
for(Guild guild : event.getJDA().getGuilds()) {
System.out.println(guild.getName());
}
if (event.isFromType(ChannelType.PRIVATE)) {
System.out.printf("[PM] %s: %s\n", event.getAuthor().getName(),
event.getMessage().getContentDisplay());
} else {
System.out.printf("[%s][%s] %s: %s\n", event.getGuild().getName(),
event.getTextChannel().getName(), Objects.requireNonNull(event.getMember()).getEffectiveName(),
event.getMessage().getContentDisplay());
}
}
}
One of the warnings that I'm getting on the output is:
[JDA MainWS-ReadThread] INFO WebSocketClient - Connected to WebSocket
[JDA Gateway-Worker 1] WARN GuildSetupController - Automatically marking 1 guilds as unavailable due to timeout!
I'm using my boy on a single guild only (#general
) so it's not connecting to it. Is this the cause of my issue? If not, what it is? It's because my JDABuilder is deprecated? (I didn't find how to use the current JDABuilder instance shown on the official documentation on GitHub).
Upvotes: 0
Views: 1076