Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FieldsEmbed<Element>

A pagination mode that uses a MessageEmbed with a field(s) containing the elements to paginate.

Type parameters

  • Element

Hierarchy

Constructors

constructor

Events

on

  • on(event: "start", listener: function): FieldsEmbed<Element>
  • on(event: "finish", listener: ListenerUser): FieldsEmbed<Element>
  • on(event: "pageUpdate", listener: function): FieldsEmbed<Element>
  • on(event: "react", listener: ListenerReact): FieldsEmbed<Element>
  • on(event: "expire", listener: function): FieldsEmbed<Element>
  • on(event: "error", listener: ListenerError): FieldsEmbed<Element>
  • Emitted after the initial embed has been sent (technically, after the client finished reacting with enabled navigation and function emojis).

    Parameters

    • event: "start"
    • listener: function
        • (): void
        • Returns void

    Returns FieldsEmbed<Element>

  • Emitted when the instance is finished by a user reacting with delete navigation emoji or a function emoji that throws non-Error type.

    Parameters

    • event: "finish"
    • listener: ListenerUser

    Returns FieldsEmbed<Element>

  • Emitted after the page number is updated and before the client sends the embed.

    Parameters

    • event: "pageUpdate"
    • listener: function
        • (): void
        • Returns void

    Returns FieldsEmbed<Element>

  • Emitted upon a user reacting on the instance.

    Parameters

    • event: "react"
    • listener: ListenerReact

    Returns FieldsEmbed<Element>

  • Emitted when the awaiting timeout is reached.

    Parameters

    • event: "expire"
    • listener: function
        • (): void
        • Returns void

    Returns FieldsEmbed<Element>

  • Emitted upon an occurance of error.

    Parameters

    • event: "error"
    • listener: ListenerError

    Returns FieldsEmbed<Element>

Properties

array

array: Element[]

An array of elements to paginate.

authorizedUsers

authorizedUsers: string[]

The authorized users to navigate the pages. Default: everyone

channel

channel: TextChannel | DMChannel | NewsChannel

The channel where to send the embed.

clientAssets

clientAssets: ClientAssets

Settings for assets for the client.

content

The client's message content options.

deleteOnTimeout

deleteOnTimeout: boolean

Whether the client's message will be deleted upon timeout. Default: false

disabledNavigationEmojis

disabledNavigationEmojis: ("back" | "jump" | "forward" | "delete" | "all")[]

The disabled navigation emojis. Available navigation emojis to disable:

  • 'back'
  • 'jump'
  • 'forward'
  • 'delete'
  • 'all'

elementsPerPage

elementsPerPage: number

Maximum number of elements to be displayed per page.

embed

embed: MessageEmbed

The MessageEmbed being used for this mode.

Notice

To customise the MessageEmbed for this mode, please access this property. Example:

<FieldsEmbed>.embed.setColor('red')

emojisFunctionAfterNavigation

emojisFunctionAfterNavigation: boolean

Whether to set function emojis after navigation emojis. Default: false

functionEmojis

functionEmojis: FunctionEmoji<Element>

The emojis used for function emojis. Function emojis are user-customised message reactions for modifying the current instance of the pagination such as modifying embed texts, stopping the pagination, etc.

navigationEmojis

navigationEmojis: NavigationEmojis

The emojis used for navigation emojis. Navigation emojis are the default message reactions for navigating through the pagination.

page

page: number

The current page. Default: 1

timeout

timeout: number

The time for awaiting a user action before timeout in ms. Default: 30000

usePageIndicator

usePageIndicator: boolean | "footer"

Whether to show page indicator, or put it in embed's footer text (replaces the existing text) instead. Default: false

Accessors

elementList

  • get elementList(): Element[]
  • Elements in the current page.

    Returns Element[]

pageIndicator

  • get pageIndicator(): string
  • The formatted page indicator. Default format: text

    Returns string

pages

  • get pages(): number
  • Number of pages for this instance.

    Returns number

Methods

addFunctionEmoji

  • addFunctionEmoji(emoji: string, callback: function): FieldsEmbed<Element>
  • Adds a function emoji to the embed.

    Example

     <PaginationEmbed>.addFunctionEmoji('πŸ…±', (_, instance) => {
       const field = instance.embed.fields[0];
    
       if (field.name.includes('πŸ…±'))
         field.name = 'Name';
       else
         field.name = 'NaπŸ…±e';
     });
    

    Parameters

    • emoji: string

      The emoji to use as the function's emoji.

    • callback: function

      The function to call upon pressing the function emoji.

    Returns FieldsEmbed<Element>

build

  • build(): Promise<void>
  • Build the Pagination Fields Embed.

    Example

      const { FieldsEmbed } = require('discord-paginationembed');
    
      // Under message event.
      new FieldsEmbed()
       .setAuthorizedUsers([message.author.id])
       .setChannel(message.channel)
       .setClientAssets({ prompt: 'Yo {{user}} wat peige?!?!?' })
       .setArray([{ name: 'John Doe' }, { name: 'Jane Doe' }])
       .setElementsPerPage(1)
       .setPageIndicator(false)
       .formatField('Name', el => el.name)
       .setPage(1)
       .setTimeout(69000)
       .setNavigationEmojis({
         back: 'β—€',
         jump: 'β†—',
         forward: 'β–Ά',
         delete: 'πŸ—‘'
       })
       .setFunctionEmojis({
         'πŸ”„': (user, instance) => {
           const field = instance.embed.fields[0];
    
           if (field.name === 'Name')
             field.name = user.tag;
           else
             field.name = 'Name';
         }
       })
       .build();```
    

    Returns Promise<void>

deleteFunctionEmoji

  • deleteFunctionEmoji(emoji: string): FieldsEmbed<Element>

formatField

  • formatField(name: string, value: function, inline?: boolean): FieldsEmbed<Element>
  • Adds a field to the embed. Same as MessageEmbed.addField, but value takes a function instead.

    Parameters

    • name: string

      Name of the field.

    • value: function

      Value of the field. Function for Array.prototype.map().join('\n').

        • (element: Element, index?: number, array?: Element[]): any
        • Parameters

          • element: Element
          • Optional index: number
          • Optional array: Element[]

          Returns any

    • inline: boolean = true

      Whether the field is inline with other field. Default: true

    Returns FieldsEmbed<Element>

resetEmojis

setArray

  • Sets the array of elements to paginate. This must be called first before any other methods.

    Parameters

    • array: Element[]

      An array of elements to paginate.

    Returns FieldsEmbed<Element>

setAuthorizedUsers

  • setAuthorizedUsers(users: string | string[]): FieldsEmbed<Element>
  • Set the authorized users to navigate the pages.

    Parameters

    • users: string | string[]

      A user ID or an array of user IDs.

    Returns FieldsEmbed<Element>

setChannel

  • setChannel(channel: TextChannel | DMChannel | NewsChannel): FieldsEmbed<Element>
  • The channel where to send the embed.

    Parameters

    • channel: TextChannel | DMChannel | NewsChannel

      The channel object.

    Returns FieldsEmbed<Element>

setClientAssets

setContent

  • setContent(text: any, separator?: string): FieldsEmbed<Element>
  • Sets the client's message content.

    Parameters

    • text: any

      The message content.

    • separator: string = '\n'

      The string to separate the content from the page indicator.

    Returns FieldsEmbed<Element>

setDeleteOnTimeout

  • setDeleteOnTimeout(boolean: boolean): FieldsEmbed<Element>

setDisabledNavigationEmojis

  • Sets the disabled navigation emojis.

    Example

     // Disable specific navigation emojis
     <PaginationEmbed>.setDisabledNavigationEmojis(['delete', 'jump']);
    
     // Disable all navigation emojis
     <PaginationEmbed>.setDisabledNavigationEmojis(['all']);
    

    Parameters

    Returns FieldsEmbed<Element>

setElementsPerPage

  • setElementsPerPage(max: number): FieldsEmbed<Element>
  • Sets the maximum number of elements to be displayed per page.

    Parameters

    • max: number

      Maximum number of elements to be displayed per page.

    Returns FieldsEmbed<Element>

setEmojisFunctionAfterNavigation

  • setEmojisFunctionAfterNavigation(boolean: boolean): FieldsEmbed<Element>

setFunctionEmojis

  • Sets the emojis used for function emojis.

    Example

     <PaginationEmbed>.setFunctionEmojis({
       'πŸ”„': (user, instance) => {
         const field = instance.embed.fields[0];
    
         if (field.name === 'Name')
           field.name = user.tag;
         else
           field.name = 'Name';
       }
     });
    

    Parameters

    • emojis: FunctionEmoji<Element>

      An object containing customised emojis to use as function emojis.

    Returns FieldsEmbed<Element>

setNavigationEmojis

setPage

  • setPage(page: number | "back" | "forward"): FieldsEmbed<Element>
  • Sets to jump to a certain page upon calling PaginationEmbed.build().

    Parameters

    • page: number | "back" | "forward"

      The page number to jump to.

    Returns FieldsEmbed<Element>

setPageIndicator

  • Sets the page indicator formatting function and placement.

    Parameters

    • enabled: boolean | "footer"

      Whether to show page indicator. Pass footer to display the indicator in embed's footer text (replaces existing text) instead.

    • Optional fn: PageIndicatorCaster | PageIndicatorPreMadeTypes

      Function for indicator formatting.

    Returns FieldsEmbed<Element>

setTimeout

  • Sets the time for awaiting a user action before timeout in ms.

    Parameters

    • timeout: number

      Timeout value in ms.

    Returns FieldsEmbed<Element>

Generated using TypeDoc