async function createEmbedsPagination(
  channelId,
  authorId,
  embeds,
  defaultPage = 1,
  reactionTimeout = Milliseconds.SECOND * 30,
  reactions = {
    // deno-lint-ignore require-await
    "◀️": async (setPage, currentPage) => setPage(Math.max(currentPage - 1, 1)),
    "↗️": async (setPage) => {
      const question = await sendMessage(
        channelId,
        "To what page would you like to jump? Say `cancel` or `0` to cancel the prompt.",
      );
      const answer = await needMessage(authorId, channelId);
      await deleteMessages(channelId, [
        question.id,
        answer.id,
      ]).catch(log.error);
      const newPageNumber = Math.ceil(Number(answer.content));
      if (isNaN(newPageNumber)) {
        return await sendMessage(channelId, "This is not a valid number!");
      }
      if (newPageNumber < 1 || newPageNumber > embeds.length) {
        return await sendMessage(channelId, `This is not a valid page!`);
      }
      setPage(newPageNumber);
    },
    // deno-lint-ignore require-await
    "▶️": async (setPage, currentPage, pageCount) =>
      setPage(Math.min(currentPage + 1, pageCount)),
    // deno-lint-ignore require-await
    "🗑️": async (_setPage, _currentPage, _pageCount, deletePagination) =>
      deletePagination(),
  },
) {
  if (embeds.length === 0) return;
  let currentPage = defaultPage;
  const embedMessage = await sendEmbed(channelId, embeds[currentPage - 1]);
  if (!embedMessage) return;
  if (embeds.length <= 1) return;
  await embedMessage.addReactions(Object.keys(reactions), true).catch(
    log.error,
  );
  let isEnded = false;
  while (!isEnded) {
    if (!embedMessage) return;
    const reaction = await needReaction(authorId, embedMessage.id, {
      duration: reactionTimeout,
    });
    if (!reaction) return;
    if (embedMessage.guildId) {
      await removeReaction(embedMessage.channelId, embedMessage.id, reaction, {
        userId: authorId,
      }).catch(log.error);
    }
    if (reactions[reaction]) {
      await reactions[reaction](
        (newPage) => {
          currentPage = newPage;
        },
        currentPage,
        embeds.length,
        async () => {
          isEnded = true;
          await embedMessage.delete().catch(log.error);
        },
      );
    }
    if (
      isEnded || !embedMessage ||
      !await editEmbed(embedMessage, embeds[currentPage - 1]).catch(log.error)
    ) {
      return;
    }
  }
}
/** This function allows to create a pagination using embeds and reactions Requires GUILD_MESSAGE_REACTIONS intent **/
This function allows to create a pagination using embeds and reactions Requires GUILD_MESSAGE_REACTIONS intent
This function allows to create a pagination using embeds and reactions Requires GUILD_MESSAGE_REACTIONS intent
async function createEmbedsPagination(
  channelId,
  authorId,
  embeds,
  defaultPage = 1,
  reactionTimeout = Milliseconds.SECOND * 30,
  reactions = {
    "◀️": async (setPage, currentPage) => setPage(Math.max(currentPage - 1, 1)),
    "↗️": async (setPage) => {
      const question = await sendMessage(
        channelId,
        "To what page would you like to jump? Say `cancel` or `0` to cancel the prompt.",
      );
      const answer = await needMessage(authorId, channelId);
      await deleteMessages(channelId, [
        question.id,
        answer.id,
      ]).catch(log.error);
      const newPageNumber = Math.ceil(Number(answer.content));
      if (isNaN(newPageNumber)) {
        return await sendMessage(channelId, "This is not a valid number!");
      }
      if (newPageNumber < 1 || newPageNumber > embeds.length) {
        return await sendMessage(channelId, `This is not a valid page!`);
      }
      setPage(newPageNumber);
    },
    "▶️": async (setPage, currentPage, pageCount) =>
      setPage(Math.min(currentPage + 1, pageCount)),
    "🗑️": async (_setPage, _currentPage, _pageCount, deletePagination) =>
      deletePagination(),
  },
) {
  if (embeds.length === 0) return;
  let currentPage = defaultPage;
  const embedMessage = await sendEmbed(channelId, embeds[currentPage - 1]);
  if (!embedMessage) return;
  if (embeds.length <= 1) return;
  await embedMessage.addReactions(Object.keys(reactions), true).catch(
    log.error,
  );
  let isEnded = false;
  while (!isEnded) {
    if (!embedMessage) return;
    const reaction = await needReaction(authorId, embedMessage.id, {
      duration: reactionTimeout,
    });
    if (!reaction) return;
    if (embedMessage.guildId) {
      await removeReaction(embedMessage.channelId, embedMessage.id, reaction, {
        userId: authorId,
      }).catch(log.error);
    }
    if (reactions[reaction]) {
      await reactions[reaction](
        (newPage) => {
          currentPage = newPage;
        },
        currentPage,
        embeds.length,
        async () => {
          isEnded = true;
          await embedMessage.delete().catch(log.error);
        },
      );
    }
    if (
      isEnded || !embedMessage ||
      !await editEmbed(embedMessage, embeds[currentPage - 1]).catch(log.error)
    ) {
      return;
    }
  }
}
async function createEmbedsPagination ( channelId , authorId , embeds , defaultPage = 1 , reactionTimeout = Milliseconds . SECOND * 30 , reactions = { "◀️": as y c (se P age, cu r entPage) => et age(Mat h .max ( cur r entPage - 1 ) ) "↗️": as y c (se P age) => const question = await sendMessage ( channelId , "To what page would you like to jump? Say `cancel` or `0` to cancel the prompt." , ) ; const answer = await needMessage ( authorId , channelId ) ; await deleteMessages ( channelId , [ question . id , answer . id , ] ) . catch ( log . error ) ; const newPageNumber = Math . ceil ( Number ( answer . content ) ) ; if ( isNaN ( newPageNumber ) ) { return await sendMessage ( channelId , "This is not a valid number!" ) ; } if ( newPageNumber < 1 || newPageNumber > embeds . length ) { return await sendMessage ( channelId , ` ` ) ; } setPage ( newPageNumber ) ; } , "▶️": as y c (se P age, cu r entPage, pa g Count) => setPage ( Math . min ( currentPage + 1 , pageCount ) ) , "🗑️": asy n  (_se P age, _cu r entPage, _pa g Count, del e ePagination) => deletePagination ( ) , } , ) { if ( embeds . length === 0 ) return ; let currentPage = defaultPage ; const embedMessage = await sendEmbed ( channelId , embeds [ currentPage - 1 ] ) ; if ( ! embedMessage ) return ; if ( embeds . length <= 1 ) return ; await embedMessage . addReactions ( Object . keys ( reactions ) , true ) . catch ( log . error , ) ; let isEnded = false ; while ( ! isEnded ) { if ( ! embedMessage ) return ; const reaction = await needReaction ( authorId , embedMessage . id , { duration : reactionTimeout , } ) ; if ( ! reaction ) return ; if ( embedMessage . guildId ) { await removeReaction ( embedMessage . channelId , embedMessage . id , reaction , { userId : authorId , } ) . catch ( log . error ) ; } if ( reactions [ reaction ] ) { await reactions [ reaction ] ( ( newPage ) => { currentPage = newPage ; } , currentPage , embeds . length , async ( ) => { isEnded = true ; await embedMessage . delete ( ) . catch ( log . error ) ; } , ) ; } if ( isEnded || ! embedMessage || ! await editEmbed ( embedMessage , embeds [ currentPage - 1 ] ) . catch ( log . error ) ) { return ; } } }
This function allows to create a pagination using embeds and reactions Requires GUILD_MESSAGE_REACTIONS intent
This function allows to create a pagination using embeds and reactions Requires GUILD_MESSAGE_REACTIONS intent
// deno-lint-ignore require-await // deno-lint-ignore require-await // deno-lint-ignore require-await