Skip to content

Commit

Permalink
Fix IllegalStateException in Message#getCategory (#2514)
Browse files Browse the repository at this point in the history
* Fix IllegalStateException in Message#getCategory
* Handle thread channels
  • Loading branch information
Almighty-Satan committed Aug 2, 2023
1 parent 9ab2469 commit 335e0eb
Showing 1 changed file with 7 additions and 3 deletions.
Expand Up @@ -19,6 +19,7 @@
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.channel.Channel;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.attribute.ICategorizableChannel;
import net.dv8tion.jda.api.entities.channel.concrete.Category;
Expand Down Expand Up @@ -458,9 +459,12 @@ public GuildMessageChannelUnion getGuildChannel()
@Override
public Category getCategory()
{
GuildMessageChannel chan = getGuildChannel();
return chan instanceof ICategorizableChannel
? ((ICategorizableChannel) chan).getParentCategory()
Channel channel = this.channel;
if (channel instanceof ThreadChannel)
channel = ((ThreadChannel) channel).getParentChannel();

return channel instanceof ICategorizableChannel
? ((ICategorizableChannel) channel).getParentCategory()
: null;
}

Expand Down

0 comments on commit 335e0eb

Please sign in to comment.