Class CommandContext
-
- All Implemented Interfaces:
public class CommandContextContext passed to command executors
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classCommandContext.RequiredArgumentWasNullExceptionLooks 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.LoadedviewStatepublic List<Attachment<out Object>>attachments
-
Method Summary
Modifier and Type Method Description ChatInputViewModel.ViewState.LoadedgetViewState()Returns the ViewState associated with this Context List<Attachment<out Object>>getAttachments()Returns the attachments of the message that invoked this command ContextgetContext()Returns the AppContext intgetMaxFileSizeMB()Returns the maximum size attachments may be ChatInputViewModel.ViewState.Loaded.PendingReplyState.ReplyinggetReplyingState()MessageReferencegetMessageReference()Returns the MessageReference UsergetReferencedMessageAuthor()Returns the Author of the referenced message GuildMembergetReferencedMessageAuthorGuildMember()Returns the Author of the referenced message as member of the current guild MessagegetReferencedMessage()Returns the referenced message StringgetReferencedMessageLink()Returns the link of the referenced message longgetChannelId()Returns the current channel id voidsetChannelId(long id)Sets the current channel id ChannelWrappergetChannel()Returns the current channel ChannelWrappergetCurrentChannel()Returns the current channel StringgetRawContent()Returns the raw content of the message that invoked this command voidaddAttachment(String uri, String displayName)Adds an attachment voidaddAttachment(LocalAttachment attachment)Adds an attachment voidaddAttachment(Attachment<out Object> attachment)Adds an attachment List<User>getMentionedUsers()Returns the mentioned users MeUsergetMe()Returns the current user Map<String, out Object>getRawArgs()Returns the raw args booleancontainsArg(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 Objectget(String key)Gets the raw argument with the specified key ObjectgetRequired(String key)Gets the required raw argument with the specified key ObjectgetOrDefault(String key, Object defaultValue)Gets the raw argument with the specified key or the defaultValue if no such argument is present StringgetString(String key)Gets the String argument with the specified key StringgetRequiredString(String key)Gets the required String argument with the specified key StringgetStringOrDefault(String key, @NonNull() String defaultValue)Gets the String argument with the specified key or the defaultValue if no such argument is present IntegergetInt(String key)Gets the Integer argument with the specified key intgetRequiredInt(String key)Gets the required Integer argument with the specified key intgetIntOrDefault(String key, int defaultValue)Gets the Integer argument with the specified key or the defaultValue if no such argument is present LonggetLong(String key)Gets the Long argument with the specified key longgetRequiredLong(String key)Gets the required Long argument with the specified key longgetLongOrDefault(String key, long defaultValue)Gets the Long argument with the specified key or the defaultValue if no such argument is present BooleangetBool(String key)Gets the Boolean argument with the specified key booleangetRequiredBool(String key)Gets the required Boolean argument with the specified key booleangetBoolOrDefault(String key, boolean defaultValue)Gets the Boolean argument with the specified key or the defaultValue if no such argument is present UsergetUser(String key)Gets the User argument with the specified key UsergetRequiredUser(String key)Gets the required User argument with the specified key UsergetUserOrDefault(String key, User defaultValue)Gets the User argument with the specified key or the defaultValue if no such argument is present ChannelWrappergetChannel(String key)Gets the Channel argument with the specified key ChannelWrappergetRequiredChannel(String key)Gets the required channel argument with the specified key ChannelWrappergetChannelOrDefault(String key, ChannelWrapper defaultValue)Gets the channel argument with the specified key or the defaultValue if no such argument is present GuildRoleWrappergetRole(String key)Gets the Role argument with the specified key GuildRoleWrappergetRequiredRole(String key)Gets the required Role argument with the specified key GuildRoleWrappergetRoleOrDefault(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
-
-
-
-