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() or getGuildId()). 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 Details

    • getClient

      Retrieves the backing client.
      Returns:
      The client.
    • getUser

      @Pure User getUser()
      Retrieves the user.
      Returns:
      The user.
    • getMember

      @SideEffectFree default Mono<Member> 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

      @SideEffectFree default Mono<Member> getMember(Snowflake guildId)
      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

      @Pure @Nullable Snowflake getGuildId()
      Retrieves the ID of the guild, if there is one.
      Returns:
      The guild's ID, or null if a private channel.
    • isPrivate

      @Pure default boolean 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 be null to obtain a private-channel context.
      Returns:
      The new context.
    • asUser

      @SideEffectFree default AccessContext asUser(User user)
      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.