I get this error when I run the discord BOT initialisation

93 Views Asked by At
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.
[main] INFO JDA - Login Successful!
[ConcurrentSessionController-Worker-0] ERROR SessionControllerAdapter - Failed to establish connection for a node, appending to queue
java.lang.IllegalStateException: com.neovisionaries.ws.client.HostnameUnverifiedException: The certificate of the peer does not match the expected hostname (gateway.discord.gg)
  at net.dv8tion.jda.internal.requests.WebSocketClient.connect(WebSocketClient.java:414)
  at net.dv8tion.jda.internal.requests.WebSocketClient$StartingNode.run(WebSocketClient.java:1460)
  at net.dv8tion.jda.api.utils.ConcurrentSessionController$Worker.processQueue(ConcurrentSessionController.java:155)
  at net.dv8tion.jda.api.utils.ConcurrentSessionController$Worker.run(ConcurrentSessionController.java:133)
  at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: com.neovisionaries.ws.client.HostnameUnverifiedException: The certificate of the peer does not match the expected hostname (gateway.discord.gg)
  at com.neovisionaries.ws.client.SocketConnector.verifyHostname(SocketConnector.java:304)
  at com.neovisionaries.ws.client.SocketConnector.doConnect(SocketConnector.java:251)
  at com.neovisionaries.ws.client.SocketConnector.connect(SocketConnector.java:189)
  at com.neovisionaries.ws.client.WebSocket.connect(WebSocket.java:2351)
  at net.dv8tion.jda.internal.requests.WebSocketClient.connect(WebSocketClient.java:407)
  ... 4 more
public static void main(String[] args) {


        try {
            
            System.setProperty("socksProxyHost", "127.0.0.1");
            System.setProperty("socksProxyPort", "1080"); 

            SSLContext mySSLContext = SSLContext.getDefault(); 

            JDABuilder builder = JDABuilder.createDefault(TOKEN);
            builder.setWebsocketFactory(new WebSocketFactory().setSSLContext(mySSLContext).setVerifyHostname(true));
            builder.enableIntents(GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MEMBERS); //  

     
         
            builder.build();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
1

There are 1 best solutions below

0
On

Java 11 is an SSL bug in the first few versions. Can try switching to Java 17 if you are on 11. Otherwise, check your system clock is correct and that you are not connecting through a proxy