Class UserCollection

Collection of Users

Hierarchy (View Summary)

Constructors

Properties

client: Client
getUnderlyingObject: (id: string) => HydratedUser
updateUnderlyingObject: SetStoreFunction<Record<string, HydratedUser>>

Methods

  • Create a new instance of an object

    Parameters

    • id: string

      Id

    • type:
          | "user"
          | "server"
          | "channel"
          | "bot"
          | "channelUnread"
          | "channelWebhook"
          | "emoji"
          | "message"
          | "serverMember"
          | "session"

      Type

    • instance: User

      Instance

    • context: unknown

      Context

    • Optionaldata: unknown

      Data

    Returns void

  • Get or create

    Parameters

    • id: string

      Id

    • data: {
          _id: string;
          avatar?:
              | null
              | {
                  _id: string;
                  content_type: string;
                  deleted?: null
                  | boolean;
                  filename: string;
                  message_id?: null | string;
                  metadata:
                      | { type: "File" }
                      | { type: "Text" }
                      | {
                          animated?: null | boolean;
                          height: number;
                          thumbhash?: null | number[];
                          type: "Image";
                          width: number;
                      }
                      | { height: number; type: "Video"; width: number }
                      | { type: "Audio" };
                  object_id?: null | string;
                  reported?: null | boolean;
                  server_id?: null | string;
                  size: number;
                  tag: string;
                  user_id?: null | string;
              };
          badges?: number;
          bot?: null
          | { owner: string };
          discriminator: string;
          display_name?: null | string;
          flags?: number;
          online: boolean;
          privileged?: boolean;
          pronouns?: null | string;
          relations?: {
              _id: string;
              status:
                  | "User"
                  | "None"
                  | "Friend"
                  | "Outgoing"
                  | "Incoming"
                  | "Blocked"
                  | "BlockedOther";
          }[];
          relationship: | "User"
          | "None"
          | "Friend"
          | "Outgoing"
          | "Incoming"
          | "Blocked"
          | "BlockedOther";
          status?: | null
          | {
              presence?: null
              | "Online"
              | "Idle"
              | "Focus"
              | "Busy"
              | "Invisible";
              text?: null | string;
          };
          username: string;
      }

      Data

      • _id: string

        Unique Id

      • Optionalavatar?:
            | null
            | {
                _id: string;
                content_type: string;
                deleted?: null
                | boolean;
                filename: string;
                message_id?: null | string;
                metadata:
                    | { type: "File" }
                    | { type: "Text" }
                    | {
                        animated?: null | boolean;
                        height: number;
                        thumbhash?: null | number[];
                        type: "Image";
                        width: number;
                    }
                    | { height: number; type: "Video"; width: number }
                    | { type: "Audio" };
                object_id?: null | string;
                reported?: null | boolean;
                server_id?: null | string;
                size: number;
                tag: string;
                user_id?: null | string;
            }

        Avatar attachment

      • Optionalbadges?: number

        Format: uint32

      • Optionalbot?: null | { owner: string }

        Bot information

      • discriminator: string

        Discriminator

      • Optionaldisplay_name?: null | string

        Display name

      • Optionalflags?: number

        Format: uint32

      • online: boolean

        Whether this user is currently online

      • Optionalprivileged?: boolean

        Whether this user is privileged

      • Optionalpronouns?: null | string

        User's pronouns

      • Optionalrelations?: {
            _id: string;
            status:
                | "User"
                | "None"
                | "Friend"
                | "Outgoing"
                | "Incoming"
                | "Blocked"
                | "BlockedOther";
        }[]

        Relationships with other users

      • relationship:
            | "User"
            | "None"
            | "Friend"
            | "Outgoing"
            | "Incoming"
            | "Blocked"
            | "BlockedOther"

        Current session user's relationship with this user

      • Optionalstatus?:
            | null
            | {
                presence?: null
                | "Online"
                | "Idle"
                | "Focus"
                | "Busy"
                | "Invisible";
                text?: null | string;
            }

        User's current status

      • username: string

        Username

    Returns User

  • Hydrate a new instance of an object. This function does not add the object to the collection.

    Parameters

    • type:
          | "user"
          | "server"
          | "channel"
          | "bot"
          | "channelUnread"
          | "channelWebhook"
          | "emoji"
          | "message"
          | "serverMember"
          | "session"

      Type

    • context: unknown

      Context

    • data: object

      Data

    Returns HydratedUser

  • Hydrate a new user if it is not in the collection yet. This function does not add the user to the store, make sure you call addHydratedUser afterwards. This function is particularly useful when adding many users asynchronously. See Server.syncMembers for an example of this in use.

    Parameters

    • id: string

      The ID of the user

    • data: {
          _id: string;
          avatar?:
              | null
              | {
                  _id: string;
                  content_type: string;
                  deleted?: null
                  | boolean;
                  filename: string;
                  message_id?: null | string;
                  metadata:
                      | { type: "File" }
                      | { type: "Text" }
                      | {
                          animated?: null | boolean;
                          height: number;
                          thumbhash?: null | number[];
                          type: "Image";
                          width: number;
                      }
                      | { height: number; type: "Video"; width: number }
                      | { type: "Audio" };
                  object_id?: null | string;
                  reported?: null | boolean;
                  server_id?: null | string;
                  size: number;
                  tag: string;
                  user_id?: null | string;
              };
          badges?: number;
          bot?: null
          | { owner: string };
          discriminator: string;
          display_name?: null | string;
          flags?: number;
          online: boolean;
          privileged?: boolean;
          pronouns?: null | string;
          relations?: {
              _id: string;
              status:
                  | "User"
                  | "None"
                  | "Friend"
                  | "Outgoing"
                  | "Incoming"
                  | "Blocked"
                  | "BlockedOther";
          }[];
          relationship: | "User"
          | "None"
          | "Friend"
          | "Outgoing"
          | "Incoming"
          | "Blocked"
          | "BlockedOther";
          status?: | null
          | {
              presence?: null
              | "Online"
              | "Idle"
              | "Focus"
              | "Busy"
              | "Invisible";
              text?: null | string;
          };
          username: string;
      }

      The API object for a user

      • _id: string

        Unique Id

      • Optionalavatar?:
            | null
            | {
                _id: string;
                content_type: string;
                deleted?: null
                | boolean;
                filename: string;
                message_id?: null | string;
                metadata:
                    | { type: "File" }
                    | { type: "Text" }
                    | {
                        animated?: null | boolean;
                        height: number;
                        thumbhash?: null | number[];
                        type: "Image";
                        width: number;
                    }
                    | { height: number; type: "Video"; width: number }
                    | { type: "Audio" };
                object_id?: null | string;
                reported?: null | boolean;
                server_id?: null | string;
                size: number;
                tag: string;
                user_id?: null | string;
            }

        Avatar attachment

      • Optionalbadges?: number

        Format: uint32

      • Optionalbot?: null | { owner: string }

        Bot information

      • discriminator: string

        Discriminator

      • Optionaldisplay_name?: null | string

        Display name

      • Optionalflags?: number

        Format: uint32

      • online: boolean

        Whether this user is currently online

      • Optionalprivileged?: boolean

        Whether this user is privileged

      • Optionalpronouns?: null | string

        User's pronouns

      • Optionalrelations?: {
            _id: string;
            status:
                | "User"
                | "None"
                | "Friend"
                | "Outgoing"
                | "Incoming"
                | "Blocked"
                | "BlockedOther";
        }[]

        Relationships with other users

      • relationship:
            | "User"
            | "None"
            | "Friend"
            | "Outgoing"
            | "Incoming"
            | "Blocked"
            | "BlockedOther"

        Current session user's relationship with this user

      • Optionalstatus?:
            | null
            | {
                presence?: null
                | "Online"
                | "Idle"
                | "Focus"
                | "Busy"
                | "Invisible";
                text?: null | string;
            }

        User's current status

      • username: string

        Username

    Returns undefined | HydratedUser

    The HydratedUser, or undefined if the user is in the collection