Closed ubercd closed 8 years ago
The null pointer exception is in your own code. Can you upload that class to hastebin? I don't think this is a JDA issue.
Yeah, this doesn't look to be a JDA issue. provide the PingCommand class on http://hastebin.com please.
In the code you shared, line 19 is blank
Also, MessageReceivedEvent#getTextChannel() can be null if the message was a Direct/Private message
sorry, re-ran it and now it's saying line 16 rather than 19
That will throw a NPE whenever the bot gets a private message
@jagrosh what's the fix then? im just trying to get it to respond with anything obviously
If you take a look at the docs, you'll see the TextChannel extends Channel, which represents a Guild channel. MessageReceivedEvent is for both Guild and Private messages. You need to either use the MessageReceivedEvent#getPrivate() boolean to determine if you need getTextChannel() or getPrivateChannel(), or use the MessageChannel interface returned from MessageReceivedEvent#getChannel()
thanks. the bot responds correctly when pinged from the server but not private messages.
Considering that this was an error in your own code, would you mind closing this issue?
Also, if you have more questions, this channel will be an excellent resource: https://discord.gg/0SBTUU1wZTUgGuC8
Cannot get my simple ping bot to work~ getting the following errors
[21:55:03] [Fatal] [JDA]: One of the EventListeners had an uncaught exception [21:55:03] [Fatal] [JDA]: Encountered an exception: java.lang.NullPointerException at Commands.PingCommand.action(PingCommand.java:19) at Bot1.handleCommand(Bot1.java:41) at BotListener.onMessageReceived(BotListener.java:13) at net.dv8tion.jda.hooks.ListenerAdapter.onEvent(ListenerAdapter.java:176) at net.dv8tion.jda.hooks.InterfacedEventManager.handle(InterfacedEventManager.java:57) at net.dv8tion.jda.handle.MessageReceivedHandler.handleInternally(MessageReceivedHandler.java:65) at net.dv8tion.jda.handle.SocketHandler.handle(SocketHandler.java:36) at net.dv8tion.jda.requests.WebSocketClient.handleEvent(WebSocketClient.java:545) at net.dv8tion.jda.requests.WebSocketClient.onTextMessage(WebSocketClient.java:296) at com.neovisionaries.ws.client.ListenerManager.callOnTextMessage(ListenerManager.java:352) at com.neovisionaries.ws.client.ReadingThread.callOnTextMessage(ReadingThread.java:233) at com.neovisionaries.ws.client.ReadingThread.callOnTextMessage(ReadingThread.java:211) at com.neovisionaries.ws.client.ReadingThread.handleTextFrame(ReadingThread.java:910) at com.neovisionaries.ws.client.ReadingThread.handleFrame(ReadingThread.java:693) at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:102) at com.neovisionaries.ws.client.ReadingThread.run(ReadingThread.java:61)