Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Embeds

A pagination mode that uses an array of MessageEmbed to paginate.

Hierarchy

Constructors

constructor

Events

on

  • on(event: "start", listener: function): Embeds
  • on(event: "finish", listener: ListenerUser): Embeds
  • on(event: "pageUpdate", listener: function): Embeds
  • on(event: "react", listener: ListenerReact): Embeds
  • on(event: "expire", listener: function): Embeds
  • on(event: "error", listener: ListenerError): Embeds
  • 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 Embeds

  • 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 Embeds

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

    Parameters

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

    Returns Embeds

  • Emitted upon a user reacting on the instance.

    Parameters

    • event: "react"
    • listener: ListenerReact

    Returns Embeds

  • Emitted when the awaiting timeout is reached.

    Parameters

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

    Returns Embeds

  • Emitted upon an occurance of error.

    Parameters

    • event: "error"
    • listener: ListenerError

    Returns Embeds

Properties

array

array: MessageEmbed[]

An array of elements to paginate.

author

author: object

The author of all embeds.

Type declaration

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.

color

color: number

The color of all embeds.

content

The client's message content options.

deleteOnTimeout

deleteOnTimeout: boolean

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

description

description: string

The description of all embeds.

disabledNavigationEmojis

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

The disabled navigation emojis. Available navigation emojis to disable:

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

emojisFunctionAfterNavigation

emojisFunctionAfterNavigation: boolean

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

fields

fields: EmbedField[]

The fields of all embeds.

footer

footer: object

The footer of all embeds.

Type declaration

functionEmojis

functionEmojis: FunctionEmoji<MessageEmbed>

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.

image

image: string

The image of all embeds.

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

thumbnail

thumbnail: string

The thumbnail of all embeds.

timeout

timeout: number

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

timestamp

timestamp: number

The timestamp of all embeds.

title

title: string

The title of all embeds.

url

url: string

The URL of all embeds.

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

currentEmbed

  • get currentEmbed(): MessageEmbed
  • Embed in the current page.

    Returns MessageEmbed

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

addField

  • addField(name: string, value: any, inline?: boolean): Embeds
  • Adds a field to the fields of all embeds.

    Parameters

    • name: string

      The name of the field.

    • value: any

      The value of the field.

    • inline: boolean = false

      Whether the field is inline to the other fields.

    Returns Embeds

addFunctionEmoji

  • addFunctionEmoji(emoji: string, callback: function): Embeds
  • 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 Embeds

attachFiles

  • attachFiles(files: (string | FileOptions | MessageAttachment)[]): Embeds
  • Files to attach to all embeds.

    Parameters

    • files: (string | FileOptions | MessageAttachment)[]

      Files to attach.

    Returns Embeds

build

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

    Example

      const { Embeds } = require('discord-paginationembed');
      const { MessageEmbed } = require('discord.js');
    
      // Under message event.
      const embeds = [];
    
      for (let i = 0; i < 5; ++i)
       embeds.push(new MessageEmbed().addField('Page', i + 1));
    
      new Embeds()
       .setAuthorizedUsers([message.author.id])
       .setChannel(message.channel)
       .setClientAssets({ prompt: 'Yo {{user}} wat peige?!?!?' })
       .setArray(embeds)
       .setPageIndicator(false)
       .setPage(1)
       .setTimeout(69000)
       .setNavigationEmojis({
         back: 'β—€',
         jump: 'β†—',
         forward: 'β–Ά',
         delete: 'πŸ—‘'
       })
       .setFunctionEmojis({
         '⬆': (_, instance) => {
           for (const embed of instance.array)
             embed.fields[0].value++;
           },
         '⬇': (_, instance) => {
            for (const embed of instance.array)
              embed.fields[0].value--;
           }
       })
       .setDescription('This is one of my embeds with this message!')
       .setColor(0xFF00AE)
       .setTimestamp()
       .build();```
    

    Returns Promise<void>

deleteFunctionEmoji

  • deleteFunctionEmoji(emoji: string): Embeds

resetEmojis

  • Deletes all function emojis, and then re-enables all navigation emojis.

    Returns Embeds

setArray

  • setArray(array: MessageEmbed[]): Embeds
  • Sets the array of MessageEmbed to paginate.

    Parameters

    • array: MessageEmbed[]

      An array of MessageEmbed to paginate.

    Returns Embeds

setAuthor

  • setAuthor(name: string, iconURL?: string, url?: string): Embeds
  • Set the author of all embeds.

    Parameters

    • name: string

      The name of the author.

    • Optional iconURL: string

      The icon URL of the author.

    • Optional url: string

      The URL of the author.

    Returns Embeds

setAuthorizedUsers

  • setAuthorizedUsers(users: string | string[]): Embeds
  • Set the authorized users to navigate the pages.

    Parameters

    • users: string | string[]

      A user ID or an array of user IDs.

    Returns Embeds

setChannel

  • setChannel(channel: TextChannel | DMChannel | NewsChannel): Embeds
  • The channel where to send the embed.

    Parameters

    • channel: TextChannel | DMChannel | NewsChannel

      The channel object.

    Returns Embeds

setClientAssets

setColor

  • setColor(color: ColorResolvable): Embeds
  • Sets the color of all embeds.

    Parameters

    • color: ColorResolvable

      The color of all embeds.

    Returns Embeds

setContent

  • setContent(text: any, separator?: string): Embeds
  • 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 Embeds

setDeleteOnTimeout

  • setDeleteOnTimeout(boolean: boolean): Embeds

setDescription

  • setDescription(description: any): Embeds
  • Sets the description of all embeds.

    Parameters

    • description: any

      The description of all embeds.

    Returns Embeds

setDisabledNavigationEmojis

  • Sets the disabled navigation emojis.

    Example

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

    Parameters

    Returns Embeds

setEmojisFunctionAfterNavigation

  • setEmojisFunctionAfterNavigation(boolean: boolean): Embeds

setFooter

  • setFooter(text: any, iconURL?: string): Embeds
  • Sets the footer of all embeds.

    Parameters

    • text: any

      The footer text.

    • Optional iconURL: string

      URL for the footer's icon.

    Returns Embeds

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<MessageEmbed>

      An object containing customised emojis to use as function emojis.

    Returns Embeds

setImage

  • setImage(url: string): Embeds
  • Sets the image of all embeds.

    Parameters

    • url: string

      The image of all embeds.

    Returns Embeds

setNavigationEmojis

setPage

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

    Parameters

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

      The page number to jump to.

    Returns Embeds

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 Embeds

setThumbnail

  • setThumbnail(url: string): Embeds
  • Sets the thumbnail of all embeds.

    Parameters

    • url: string

      The thumbnail of all embeds.

    Returns Embeds

setTimeout

  • setTimeout(timeout: number): Embeds
  • Sets the time for awaiting a user action before timeout in ms.

    Parameters

    • timeout: number

      Timeout value in ms.

    Returns Embeds

setTimestamp

  • setTimestamp(timestamp?: number | Date): Embeds
  • Sets the timestamp of all embeds.

    Parameters

    • Optional timestamp: number | Date

      The timestamp or date.

    Returns Embeds

setTitle

  • setTitle(title: any): Embeds
  • Sets the title of all embeds.

    Parameters

    • title: any

      The title of all embeds.

    Returns Embeds

setURL

  • Sets the URL of all embeds.

    Parameters

    • url: string

      The URL of all embeds.

    Returns Embeds

spliceFields

  • spliceFields(index: number, deleteCount: number, name?: any, value?: any, inline?: boolean): Embeds
  • Removes, replaces, and inserts fields in all embeds (max 25).

    Parameters

    • index: number

      The index to start at.

    • deleteCount: number

      The number of fields to remove.

    • Optional name: any

      The name of the field.

    • Optional value: any

      The value of the field.

    • Optional inline: boolean

      Set the field to display inline.

    Returns Embeds

toJSON

  • toJSON(): object[]
  • Transforms all embeds to plain objects.

    Returns object[]

Generated using TypeDoc