Class GenericMessageEvent
- java.lang.Object
-
- net.dv8tion.jda.api.events.Event
-
- net.dv8tion.jda.api.events.message.GenericMessageEvent
-
- All Implemented Interfaces:
GenericEvent
- Direct Known Subclasses:
GenericMessageReactionEvent,MessageDeleteEvent,MessageEmbedEvent,MessageReactionRemoveAllEvent,MessageReactionRemoveEmoteEvent,MessageReceivedEvent,MessageUpdateEvent
public abstract class GenericMessageEvent extends Event
Indicates that aMessagewas created/deleted/changed.
Every MessageEvent is an instance of this event and can be casted.Can be used to detect any MessageEvent.
Requirements
These events require at least one of the following intents (Will not fire at all if neither is enabled):
GUILD_MESSAGESto work in guild text channelsDIRECT_MESSAGESto work in private channels
-
-
Constructor Summary
Constructors Constructor Description GenericMessageEvent(JDA api, long responseNumber, long messageId, MessageChannel channel)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MessageChannelgetChannel()TheMessageChannelfor this MessageChannelTypegetChannelType()TheChannelTypefor this messageGuildgetGuild()TheGuildthe Message was received in.GuildMessageChannelgetGuildChannel()TheGuildMessageChannelfor this Message if it was sent in a Guild.StringgetMessageId()The id for this messagelonggetMessageIdLong()The id for this messageNewsChannelgetNewsChannel()TheNewsChannelthe Message was received in.PrivateChannelgetPrivateChannel()ThePrivateChannelthe Message was received in.TextChannelgetTextChannel()TheTextChannelthe Message was received in.ThreadChannelgetThreadChannel()TheThreadChannelthe Message was received in.booleanisFromGuild()Whether this message was sent in aGuild.booleanisFromThread()If the message event was from aThreadChannelbooleanisFromType(ChannelType type)Indicates whether the message is from the specifiedChannelType-
Methods inherited from class net.dv8tion.jda.api.events.Event
getJDA, getResponseNumber
-
-
-
-
Constructor Detail
-
GenericMessageEvent
public GenericMessageEvent(@Nonnull JDA api, long responseNumber, long messageId, @Nonnull MessageChannel channel)
-
-
Method Detail
-
getChannel
@Nonnull public MessageChannel getChannel()
TheMessageChannelfor this Message- Returns:
- The MessageChannel
-
getGuildChannel
@Nonnull public GuildMessageChannel getGuildChannel()
TheGuildMessageChannelfor this Message if it was sent in a Guild.
If this Message was not received from aGuild, this will throw anIllegalStateException.- Returns:
- The GuildMessageChannel
- Throws:
IllegalStateException- If this was not sent in a channel in a Guild.
-
getMessageId
@Nonnull public String getMessageId()
The id for this message- Returns:
- The id for this message
-
getMessageIdLong
public long getMessageIdLong()
The id for this message- Returns:
- The id for this message
-
isFromType
public boolean isFromType(@Nonnull ChannelType type)
Indicates whether the message is from the specifiedChannelType- Parameters:
type- The ChannelType- Returns:
- True, if the message is from the specified channel type
-
isFromGuild
public boolean isFromGuild()
Whether this message was sent in aGuild.
If this isfalsethengetGuild()will throw anIllegalStateException.- Returns:
- True, if
getChannelType().isGuild()is true.
-
getChannelType
@Nonnull public ChannelType getChannelType()
TheChannelTypefor this message- Returns:
- The ChannelType
-
getGuild
@Nonnull public Guild getGuild()
TheGuildthe Message was received in.
If this Message was not received in aTextChannel, this will throw anIllegalStateException.- Returns:
- The Guild the Message was received in
- Throws:
IllegalStateException- If this was not sent in aGuildChannel.- See Also:
isFromGuild(),isFromType(ChannelType),getChannelType()
-
getTextChannel
@Nonnull public TextChannel getTextChannel()
TheTextChannelthe Message was received in.
If this Message was not received in aTextChannel, this will throw anIllegalStateException.- Returns:
- The TextChannel the Message was received in
- Throws:
IllegalStateException- If this was not sent in aTextChannel.- See Also:
isFromGuild(),isFromType(ChannelType),getChannelType()
-
getNewsChannel
@Nonnull public NewsChannel getNewsChannel()
TheNewsChannelthe Message was received in.
If this Message was not received in aNewsChannel, this will throw anIllegalStateException.- Returns:
- The NewsChannel the Message was received in
- Throws:
IllegalStateException- If this was not sent in aNewsChannel.- See Also:
isFromGuild(),isFromType(ChannelType),getChannelType()
-
getPrivateChannel
@Nonnull public PrivateChannel getPrivateChannel()
ThePrivateChannelthe Message was received in.
If this Message was not received in aPrivateChannel, this will throw anIllegalStateException.- Returns:
- The PrivateChannel the Message was received in
- Throws:
IllegalStateException- If this was not sent in aPrivateChannel.- See Also:
isFromGuild(),isFromType(ChannelType),getChannelType()
-
getThreadChannel
@Nonnull public ThreadChannel getThreadChannel()
TheThreadChannelthe Message was received in.
If this Message was not received in aThreadChannel, this will throw anIllegalStateException.- Returns:
- The ThreadChannel the Message was received in
- Throws:
IllegalStateException- If this was not sent in aThreadChannel.- See Also:
isFromGuild(),isFromType(ChannelType),getChannelType(),isFromThread()
-
isFromThread
public boolean isFromThread()
If the message event was from aThreadChannel- Returns:
- If the message event was from a ThreadChannel
- See Also:
ChannelType.isThread()
-
-