I am facing an issue while attempting to initialize my Discord bot, receiving the following error messages:
SLF4J: No SLF4J providers found.
SLF4J: Defaulting to no-operation (NOP) logger.
SLF4J: Refer to the SLF4J documentation for details.
[main] INFO JDA - Successful Login!
[SessionWorker-0] ERROR SessionHandler - Connection for a node failed, added to queue.
java.lang.IllegalStateException: com.neovisionaries.ws.client.HostnameUnverifiedException: Peer certificate does not match hostname (gateway.discord.gg)
at net.dv8tion.jda.internal.requests.WebSocketClient.connect(WebSocketClient.java:414)
...
Caused by: com.neovisionaries.ws.client.HostnameUnverifiedException: Peer certificate mismatch (gateway.discord.gg)
at com.neovisionaries.ws.client.SocketConnector.verifyHostname(SocketConnector.java:304)
...
Here’s the code I’m using:
public static void main(String[] args) {
try {
System.setProperty("proxyHost", "127.0.0.1");
System.setProperty("proxyPort", "1080");
SSLContext sslContext = SSLContext.getDefault();
JDABuilder botBuilder = JDABuilder.createDefault(TOKEN);
botBuilder.setWebsocketFactory(new WebSocketFactory().setSSLContext(sslContext).setVerifyHostname(true));
botBuilder.enableIntents(GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MEMBERS);
botBuilder.build();
} catch (Exception e) {
e.printStackTrace();
}
}