Guild object on MessageReceivedEvent shouldn't be Nonnull
General Troubleshooting
- [x] I have checked for similar issues.
- [x] I have updated to the latest JDA version.
- [x] I have checked the branches or the maintainers' PRs for upcoming bug fixes.
Bug Report
The guild object of the MessageReceivedEvent is set to Nonnull, even though it could be a private message. Same story for the guild object in the message object of the MessageReceivedEvent. If that occurs, you will receive an exception.
Expected Behavior
I think it should be nullable as the Discord API message object states guild_id to be nullable.
Code Example or Reproduction Steps
class MessageReceivedListener : ListenerAdapter() {
override fun onMessageReceived(@Nonnull event: MessageReceivedEvent) {
println(event.guild.id)
}
}
Then DM the bot.
Code for JDABuilder or DefaultShardManagerBuilder Used
N/A
Exception or Error
java.lang.IllegalStateException: This message event did not happen in a text channel
getGuild never returns null. It instead will throw an exception if the event did not happen in a text channel as documented. So the @Nonnull annotation is correct.
Use MessageReceivedEvent#isFromGuild to avoid this exception
This is not a bug.