Skip to content

See if a message mentions @here

I want to see if a message mentions @here on Discord using the JDA library for Java.

I can already see if a message mentions @everyone using net.dv8tion.jda.api.entities.Message#mentionsEveryone() but how do I see if the message mentions @here as well?

I’ve been looking into Message#getMentions(Message.MentionType...) but I’m not sure how to use it correctly as it returns the type IMentionable.



You just have to check message.mentionsEveryone() && message.getContentRaw().contains("@here"). The mentionsEveryone() method checks whether it was an everyone mention, @here counts as one since it does mention everyone who is online at the time. To see whether it was @here or @everyone you can simply check the content of the message for the literal @here or @everyone using contains("...") for each type respectively.

User contributions licensed under: CC BY-SA
7 People found this is helpful