Interface AccessContext
- All Known Subinterfaces:
ChannelAccessContext,CommandContext,InstrumentedContext,InteractionCommandContext,LazyContext,MessageCommandContext,SlashCommandContext
- All Known Implementing Classes:
MessageContextImpl
public interface AccessContext
Context around the access of a program function by a user.
- Since:
- 1.0
- Version:
- 1.0
- Implementation Requirements:
- A context must be effectively constant; that is, an implementation of this interface
must always return the same value on methods that return a direct value (such as
getUser()orgetGuildId()). Methods that fetch remote resources (i.e. that return a Mono) may return different objects over time (as the remote object is modified), but must always reference the same entity.
-
Method Summary
Modifier and TypeMethodDescriptiondefault AccessContextCreates a copy of this context with the guild replaced by the given guild.default AccessContextCreates a copy of this context with the user replaced by the given user.Retrieves the backing client.getGuild()Retrieves the guild, if there is one.Retrieves the ID of the guild, if there is one.Retrieves the user as a guild member.Retrieves the user as a guild member of the given guild.getUser()Retrieves the user.default booleanDetermines if this context is a private channel.
-
Method Details
-
getClient
Retrieves the backing client.- Returns:
- The client.
-
getUser
Retrieves the user.- Returns:
- The user.
-
getMember
Retrieves the user as a guild member.- Returns:
- The calling user as a guild member. May be empty if the context is a private channel.
- Implementation Requirements:
- The default implementation delegates to
getMember(Snowflake). It may (and should) be overriden to use existing instances when possible to avoid API calls.
-
getMember
Retrieves the user as a guild member of the given guild.- Parameters:
guildId- The ID of the target guild.- Returns:
- The user as a guild member of the given guild.
- Implementation Note:
- The default implementation deletegates to
getUser().asMember(). It may (and should) be overriden to use existing instances when possible to avoid API calls.
-
getGuild
Retrieves the guild, if there is one.- Returns:
- The invoking guild.
-
getGuildId
Retrieves the ID of the guild, if there is one.- Returns:
- The guild's ID, or
nullif a private channel.
-
isPrivate
Determines if this context is a private channel.- Returns:
- Whether the context is a private channel.
-
asGuild
Creates a copy of this context with the guild replaced by the given guild.All associated values are also replaced accordingly.
- Parameters:
guild- The target guild. May benullto obtain a private-channel context.- Returns:
- The new context.
-
asUser
Creates a copy of this context with the user replaced by the given user.All associated values are also replaced accordingly.
- Parameters:
user- The target user.- Returns:
- The new context.
-