Reputation: 31
I think this is a pretty simple question with an even more simple answer but I seriously can't manage to find out if the text channel that the event occurs in is private or not. Anyways, here's a segment of my code:
@Override
public void onMessageReceived(MessageReceivedEvent e)
{
if (e.isFromType(ChannelType.PRIVATE)) {
System.out.println("locked channel");
} else {
System.out.println("not locked");
}
}
I want it to spit out whether the channel that I type in is private or not and that code always says its "not locked".
Upvotes: 1
Views: 1105
Reputation: 31
So I found out a way to detect private channels now. Just gonna send this here for anyone else who encounters my issue
@Override
public void onMessageReceived(MessageReceivedEvent e) {
PermissionOverride po = e.getTextChannel().getPermissionOverride((IPermissionHolder) e.getGuild().getRolesByName("@everyone", true).toArray() [0]);
if (po != null && po.getDenied().contains(Permission.MESSAGE_READ)) {
//System.out.println("locked channel");
}
}
Upvotes: 2
Reputation: 36
I assume you want to know whether the message received is from a direct message. (a private channel is a direct message basically) You might want to try to override the onPrivateMessageReceived() method.
@Override
public void onPrivateMessageReceived(final PrivateMessageReceivedEvent event) {
// your code here handling DM messages
}
When this method is triggered, it will only handle the direct messages received.
Upvotes: 1