Interface AccessContext

All Known Subinterfaces:
ApplicationCommandEventContext, ButtonEventContext, ChannelAccessContext, ChannelEventContext, ComponentEventContext, DeferrableInteractionEventContext, EventContext, InteractionEventContext, MessageBasedContext, MessageCreateEventContext, MessageEventContext, MessageIncludedContext, ModalEventContext, RepliableContext, SlashCommandEventContext
All Known Implementing Classes:
AbstractChannelEventContext, AbstractEventContext, AbstractRepliableContext

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 user() or guildId()). 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

    • client

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

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

      @SideEffectFree default Mono<Member> member()
      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 member(Snowflake). It may (and should) be overriden to use existing instances when possible to avoid API calls.
    • member

      @SideEffectFree default Mono<Member> member(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 user().asMember(). It may (and should) be overriden to use existing instances when possible to avoid API calls.
    • guild

      Retrieves the guild, if there is one.
      Returns:
      The invoking guild.
    • guildId

      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.
    • of

      static AccessContext of(Member member)
      Creates an access context for the given member, in the guild that the member is from.
      Parameters:
      member - The member.
      Returns:
      The access context.
    • of

      static AccessContext of(User user, @Nullable Snowflake guild)
      Creates an access context for the given user in the given guild.
      Parameters:
      user - The user.
      guild - The guild, or null for a private channel.
      Returns:
      The access context.