Class CommandContext
-
- All Implemented Interfaces:
public class CommandContext
Context passed to command executors
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public class
CommandContext.RequiredArgumentWasNullException
Looks like Discord's required args are unreliable and are sometimes accepted even if empty. Or a plugin dev may just forget to mark an argument as required which leads to ugly NPEs. Thus, throw a custom exception and handle it in the command handler to present the user a simple message, not a scary stacktrace.
-
Field Summary
Fields Modifier and Type Field Description public final ChatInputViewModel.ViewState.Loaded
viewState
public List<Attachment<out Object>>
attachments
-
Method Summary
Modifier and Type Method Description ChatInputViewModel.ViewState.Loaded
getViewState()
Returns the ViewState associated with this Context List<Attachment<out Object>>
getAttachments()
Returns the attachments of the message that invoked this command Context
getContext()
Returns the AppContext int
getMaxFileSizeMB()
Returns the maximum size attachments may be ChatInputViewModel.ViewState.Loaded.PendingReplyState.Replying
getReplyingState()
MessageReference
getMessageReference()
Returns the MessageReference User
getReferencedMessageAuthor()
Returns the Author of the referenced message GuildMember
getReferencedMessageAuthorGuildMember()
Returns the Author of the referenced message as member of the current guild Message
getReferencedMessage()
Returns the referenced message String
getReferencedMessageLink()
Returns the link of the referenced message long
getChannelId()
Returns the current channel id void
setChannelId(long id)
Sets the current channel id ChannelWrapper
getChannel()
Returns the current channel ChannelWrapper
getCurrentChannel()
Returns the current channel String
getRawContent()
Returns the raw content of the message that invoked this command void
addAttachment(String uri, String displayName)
Adds an attachment void
addAttachment(LocalAttachment attachment)
Adds an attachment void
addAttachment(Attachment<out Object> attachment)
Adds an attachment List<User>
getMentionedUsers()
Returns the mentioned users MeUser
getMe()
Returns the current user Map<String, out Object>
getRawArgs()
Returns the raw args boolean
containsArg(String key)
Check if the arguments contain the specified key Map<String, out Object>
getRequiredSubCommandArgs(String key)
Gets the arguments object for the specified subcommand Map<String, out Object>
getSubCommandArgs(String key)
Gets the arguments object for the specified subcommand Object
get(String key)
Gets the raw argument with the specified key Object
getRequired(String key)
Gets the required raw argument with the specified key Object
getOrDefault(String key, Object defaultValue)
Gets the raw argument with the specified key or the defaultValue if no such argument is present String
getString(String key)
Gets the String argument with the specified key String
getRequiredString(String key)
Gets the required String argument with the specified key String
getStringOrDefault(String key, @NonNull() String defaultValue)
Gets the String argument with the specified key or the defaultValue if no such argument is present Integer
getInt(String key)
Gets the Integer argument with the specified key int
getRequiredInt(String key)
Gets the required Integer argument with the specified key int
getIntOrDefault(String key, int defaultValue)
Gets the Integer argument with the specified key or the defaultValue if no such argument is present Long
getLong(String key)
Gets the Long argument with the specified key long
getRequiredLong(String key)
Gets the required Long argument with the specified key long
getLongOrDefault(String key, long defaultValue)
Gets the Long argument with the specified key or the defaultValue if no such argument is present Boolean
getBool(String key)
Gets the Boolean argument with the specified key boolean
getRequiredBool(String key)
Gets the required Boolean argument with the specified key boolean
getBoolOrDefault(String key, boolean defaultValue)
Gets the Boolean argument with the specified key or the defaultValue if no such argument is present User
getUser(String key)
Gets the User argument with the specified key User
getRequiredUser(String key)
Gets the required User argument with the specified key User
getUserOrDefault(String key, User defaultValue)
Gets the User argument with the specified key or the defaultValue if no such argument is present ChannelWrapper
getChannel(String key)
Gets the Channel argument with the specified key ChannelWrapper
getRequiredChannel(String key)
Gets the required channel argument with the specified key ChannelWrapper
getChannelOrDefault(String key, ChannelWrapper defaultValue)
Gets the channel argument with the specified key or the defaultValue if no such argument is present GuildRoleWrapper
getRole(String key)
Gets the Role argument with the specified key GuildRoleWrapper
getRequiredRole(String key)
Gets the required Role argument with the specified key GuildRoleWrapper
getRoleOrDefault(String key, GuildRoleWrapper defaultValue)
Gets the Role argument with the specified key or the defaultValue if no such argument is present -
-
Method Detail
-
getViewState
@NonNull() ChatInputViewModel.ViewState.Loaded getViewState()
Returns the ViewState associated with this Context
-
getAttachments
@NonNull() List<Attachment<out Object>> getAttachments()
Returns the attachments of the message that invoked this command
-
getContext
Context getContext()
Returns the AppContext
-
getMaxFileSizeMB
int getMaxFileSizeMB()
Returns the maximum size attachments may be
-
getReplyingState
@Nullable() ChatInputViewModel.ViewState.Loaded.PendingReplyState.Replying getReplyingState()
-
getMessageReference
@Nullable() MessageReference getMessageReference()
Returns the MessageReference
-
getReferencedMessageAuthor
@Nullable() User getReferencedMessageAuthor()
Returns the Author of the referenced message
-
getReferencedMessageAuthorGuildMember
@Nullable() GuildMember getReferencedMessageAuthorGuildMember()
Returns the Author of the referenced message as member of the current guild
-
getReferencedMessage
@Nullable() Message getReferencedMessage()
Returns the referenced message
-
getReferencedMessageLink
@Nullable() String getReferencedMessageLink()
Returns the link of the referenced message
-
getChannelId
long getChannelId()
Returns the current channel id
-
setChannelId
void setChannelId(long id)
Sets the current channel id
-
getChannel
@NonNull()@Deprecated() ChannelWrapper getChannel()
Returns the current channel
-
getCurrentChannel
@NonNull() ChannelWrapper getCurrentChannel()
Returns the current channel
-
getRawContent
String getRawContent()
Returns the raw content of the message that invoked this command
-
addAttachment
void addAttachment(String uri, String displayName)
Adds an attachment
- Parameters:
uri
- Uri of the attachmentdisplayName
- file name
-
addAttachment
void addAttachment(LocalAttachment attachment)
Adds an attachment
- Parameters:
attachment
- Attachment
-
addAttachment
void addAttachment(Attachment<out Object> attachment)
Adds an attachment
- Parameters:
attachment
- Attachment
-
getMentionedUsers
List<User> getMentionedUsers()
Returns the mentioned users
-
getRawArgs
@NonNull() Map<String, out Object> getRawArgs()
Returns the raw args
-
containsArg
boolean containsArg(String key)
Check if the arguments contain the specified key
- Parameters:
key
- Key to check
-
getRequiredSubCommandArgs
@NonNull() Map<String, out Object> getRequiredSubCommandArgs(String key)
Gets the arguments object for the specified subcommand
- Parameters:
key
- Key of the subcommand
-
getSubCommandArgs
@Nullable() Map<String, out Object> getSubCommandArgs(String key)
Gets the arguments object for the specified subcommand
- Parameters:
key
- Key of the subcommand
-
get
@Nullable() Object get(String key)
Gets the raw argument with the specified key
- Parameters:
key
- The key of the argument
-
getRequired
@NonNull() Object getRequired(String key)
Gets the required raw argument with the specified key
- Parameters:
key
- The key of the argument
-
getOrDefault
@NonNull() Object getOrDefault(String key, Object defaultValue)
Gets the raw argument with the specified key or the defaultValue if no such argument is present
- Parameters:
key
- The key of the argumentdefaultValue
- The default value
-
getString
@Nullable() String getString(String key)
Gets the String argument with the specified key
- Parameters:
key
- The key of the argument
-
getRequiredString
@NonNull() String getRequiredString(String key)
Gets the required String argument with the specified key
- Parameters:
key
- The key of the argument
-
getStringOrDefault
@NonNull() String getStringOrDefault(String key, @NonNull() String defaultValue)
Gets the String argument with the specified key or the defaultValue if no such argument is present
- Parameters:
key
- The key of the argument
-
getInt
@Nullable() Integer getInt(String key)
Gets the Integer argument with the specified key
- Parameters:
key
- The key of the argument
-
getRequiredInt
int getRequiredInt(String key)
Gets the required Integer argument with the specified key
- Parameters:
key
- The key of the argument
-
getIntOrDefault
int getIntOrDefault(String key, int defaultValue)
Gets the Integer argument with the specified key or the defaultValue if no such argument is present
- Parameters:
key
- The key of the argument
-
getLong
@Nullable() Long getLong(String key)
Gets the Long argument with the specified key
- Parameters:
key
- The key of the argument
-
getRequiredLong
long getRequiredLong(String key)
Gets the required Long argument with the specified key
- Parameters:
key
- The key of the argument
-
getLongOrDefault
long getLongOrDefault(String key, long defaultValue)
Gets the Long argument with the specified key or the defaultValue if no such argument is present
- Parameters:
key
- The key of the argument
-
getBool
@Nullable() Boolean getBool(String key)
Gets the Boolean argument with the specified key
- Parameters:
key
- The key of the argument
-
getRequiredBool
boolean getRequiredBool(String key)
Gets the required Boolean argument with the specified key
- Parameters:
key
- The key of the argument
-
getBoolOrDefault
boolean getBoolOrDefault(String key, boolean defaultValue)
Gets the Boolean argument with the specified key or the defaultValue if no such argument is present
- Parameters:
key
- The key of the argument
-
getUser
@Nullable() User getUser(String key)
Gets the User argument with the specified key
- Parameters:
key
- The key of the argument
-
getRequiredUser
@NonNull() User getRequiredUser(String key)
Gets the required User argument with the specified key
- Parameters:
key
- The key of the argument
-
getUserOrDefault
@NonNull() User getUserOrDefault(String key, User defaultValue)
Gets the User argument with the specified key or the defaultValue if no such argument is present
- Parameters:
key
- The key of the argument
-
getChannel
@Nullable() ChannelWrapper getChannel(String key)
Gets the Channel argument with the specified key
- Parameters:
key
- Key of the argument
-
getRequiredChannel
@NonNull() ChannelWrapper getRequiredChannel(String key)
Gets the required channel argument with the specified key
- Parameters:
key
- The key of the argument
-
getChannelOrDefault
@NonNull() ChannelWrapper getChannelOrDefault(String key, ChannelWrapper defaultValue)
Gets the channel argument with the specified key or the defaultValue if no such argument is present
- Parameters:
key
- The key of the argument
-
getRole
@Nullable() GuildRoleWrapper getRole(String key)
Gets the Role argument with the specified key
- Parameters:
key
- Key of the argument
-
getRequiredRole
@NonNull() GuildRoleWrapper getRequiredRole(String key)
Gets the required Role argument with the specified key
- Parameters:
key
- Key of the argument
-
getRoleOrDefault
@NonNull() GuildRoleWrapper getRoleOrDefault(String key, GuildRoleWrapper defaultValue)
Gets the Role argument with the specified key or the defaultValue if no such argument is present
- Parameters:
key
- The key of the argument
-
-
-
-