async function _createAndSendEmbed(nowPlaying, audioQueue, authorId, interaction) {
  /**
   * Create a queue message embed.
   * @param {import('../../typedefs/audio').Audio[]} pageData - page data to display (up next)
   * @returns {MessageEmbed}
   */
  function createQueueEmbed(pageData) {
    const embed = embeds.base();

    // Format data for up next
    const upNextData = pageData.map((audio, i) => {
      const itemNum = page * itemsPerPage + i + 1;
      return `${itemNum}. [${audio.title}](${audio.url}) (${audio.length}), added by \`${audio.addedBy}\``;
    });

    // Set description (limit 4096 chars, title is 19 chars, 10 songs is approx 1678 chars, footer is 17 chars)
    const description =
      '**Now playing**\n' +
      `[${nowPlaying.title}](${nowPlaying.url}) (${nowPlaying.length}), added by \`${nowPlaying.addedBy}\`\n\n` +
      '**Up next**\n' +
      upNextData.join('\n') +
      `\n\n**Songs in queue:** ${audioQueue.length}`;
    embed.setDescription(description);

    // Set description
    embed.setFooter(`Page ${page + 1} of ${pages.length}`);

    return embed;
  }

  /**
   * Detect if backwards reaction was pressed.
   * @param {MessageReaction} reaction
   * @param {User} user
   * @returns {boolean}
   */
  const backwardFilter = (reaction, user) =>
    reaction.emoji.name === emoji.leftArrow && user.id === authorId;

  /**
   * Detect if forwards reaction was pressed.
   * @param {MessageReaction} reaction
   * @param {User} user
   * @returns {boolean}
   */
  const forwardFilter = (reaction, user) =>
    reaction.emoji.name === emoji.rightArrow && user.id === authorId;

  /**
   * Backward button reaction handler.
   * Go back a page in the embed if not at the first page.
   * @param {MessageReaction} reaction
   * @param {User} user
   * @returns {void}
   */
  const backwardHandler = (reaction, user) => {
    if (page === 0) return;
    page--;
    embedMessage.edit({ embeds: [createQueueEmbed(pages[page])] });
  };

  /**
   * Forward button reaction handler.
   * Go forward a page in the embed if not at the last page.
   * @param {MessageReaction} reaction
   * @param {User} user
   * @returns {void}
   */
  const forwardHandler = (reaction, user) => {
    if (page === pages.length - 1) return;
    page++;
    embedMessage.edit({ embeds: [createQueueEmbed(pages[page])] });
  };

  // If no more songs in queue, send a simple embed only
  if (!audioQueue.length) {
    return await interaction.reply({ embeds: [embeds.nowPlayingOnly(nowPlaying)] });
  }

  // Initialise
  let page = 0;
  const itemsPerPage = 10;
  const pages = _.chunk(audioQueue, itemsPerPage);
  const reactionTime = 120000;

  // Create and send initial embed
  const embed = createQueueEmbed(pages[0]);
  const embedMessage = await interaction.reply({ embeds: [embed], fetchReply: true });

  // If there is only 1 page do not set up buttons
  if (pages.length === 1) return;
  await Promise.all([embedMessage.react(emoji.leftArrow), embedMessage.react(emoji.rightArrow)]);

  // Reaction collectors
  const backwards = embedMessage.createReactionCollector({
    filter: backwardFilter,
    time: reactionTime,
    dispose: true,
  });
  const forwards = embedMessage.createReactionCollector({
    filter: forwardFilter,
    time: reactionTime,
    dispose: true,
  });

  // Reaction events
  backwards.on('collect', backwardHandler);
  backwards.on('remove', backwardHandler);
  forwards.on('collect', forwardHandler);
  forwards.on('remove', forwardHandler);
}
/**
 * Create and send an embed containing details of the current queue.
 * Embed may use multiple pages.
 * @param {import('../../typedefs/audio').Audio} nowPlaying - Audio now playing
 * @param {import('../../typedefs/audio').Audio[]} audioQueue - Audio in queue
 * @param {string} authorId - ID of user who requested queue
 * @param {CommandInteraction} interaction - interaction to reply to
 * @returns {Promise<void>}
 */
Create and send an embed containing details of the current queue.
Embed may use multiple pages.
Create and send an embed containing details of the current queue . Embed may use multiple pages .
async function _createAndSendEmbed(nowPlaying, audioQueue, authorId, interaction) {
  function createQueueEmbed(pageData) {
    const embed = embeds.base();
    const upNextData = pageData.map((audio, i) => {
      const itemNum = page * itemsPerPage + i + 1;
      return `${itemNum}. [${audio.title}](${audio.url}) (${audio.length}), added by \`${audio.addedBy}\``;
    });
    const description =
      '**Now playing**\n' +
      `[${nowPlaying.title}](${nowPlaying.url}) (${nowPlaying.length}), added by \`${nowPlaying.addedBy}\`\n\n` +
      '**Up next**\n' +
      upNextData.join('\n') +
      `\n\n**Songs in queue:** ${audioQueue.length}`;
    embed.setDescription(description);
    embed.setFooter(`Page ${page + 1} of ${pages.length}`);
    return embed;
  }
  const backwardFilter = (reaction, user) =>
    reaction.emoji.name === emoji.leftArrow && user.id === authorId;
  const forwardFilter = (reaction, user) =>
    reaction.emoji.name === emoji.rightArrow && user.id === authorId;
  const backwardHandler = (reaction, user) => {
    if (page === 0) return;
    page--;
    embedMessage.edit({ embeds: [createQueueEmbed(pages[page])] });
  };
  const forwardHandler = (reaction, user) => {
    if (page === pages.length - 1) return;
    page++;
    embedMessage.edit({ embeds: [createQueueEmbed(pages[page])] });
  };
  if (!audioQueue.length) {
    return await interaction.reply({ embeds: [embeds.nowPlayingOnly(nowPlaying)] });
  }
  let page = 0;
  const itemsPerPage = 10;
  const pages = _.chunk(audioQueue, itemsPerPage);
  const reactionTime = 120000;
  const embed = createQueueEmbed(pages[0]);
  const embedMessage = await interaction.reply({ embeds: [embed], fetchReply: true });
  if (pages.length === 1) return;
  await Promise.all([embedMessage.react(emoji.leftArrow), embedMessage.react(emoji.rightArrow)]);
  const backwards = embedMessage.createReactionCollector({
    filter: backwardFilter,
    time: reactionTime,
    dispose: true,
  });
  const forwards = embedMessage.createReactionCollector({
    filter: forwardFilter,
    time: reactionTime,
    dispose: true,
  });
  backwards.on('collect', backwardHandler);
  backwards.on('remove', backwardHandler);
  forwards.on('collect', forwardHandler);
  forwards.on('remove', forwardHandler);
}
async function _createAndSendEmbed ( nowPlaying , audioQueue , authorId , interaction ) { function createQueueEmbed ( pageData ) { const embed = embeds . base ( ) ; const upNextData = pageData . map ( ( audio , i ) => { const itemNum = page * itemsPerPage + i + 1 ; return ` ${ itemNum } ${ audio . title } ${ audio . url } ${ audio . length } \` ${ audio . addedBy } \` ` ; } ) ; const description = '**Now playing**\n' + ` ${ nowPlaying . title } ${ nowPlaying . url } ${ nowPlaying . length } \` ${ nowPlaying . addedBy } \` \n \n ` + '**Up next**\n' + upNextData . join ( '\n' ) + ` \n \n ${ audioQueue . length } ` ; embed . setDescription ( description ) ; embed . setFooter ( ` ${ page + 1 } ${ pages . length } ` ) ; return embed ; } const backwardFilter = ( reaction , user ) => reaction . emoji . name === emoji . leftArrow && user . id === authorId ; const forwardFilter = ( reaction , user ) => reaction . emoji . name === emoji . rightArrow && user . id === authorId ; const backwardHandler = ( reaction , user ) => { if ( page === 0 ) return ; page -- ; embedMessage . edit ( { embeds : [ createQueueEmbed ( pages [ page ] ) ] } ) ; } ; const forwardHandler = ( reaction , user ) => { if ( page === pages . length - 1 ) return ; page ++ ; embedMessage . edit ( { embeds : [ createQueueEmbed ( pages [ page ] ) ] } ) ; } ; if ( ! audioQueue . length ) { return await interaction . reply ( { embeds : [ embeds . nowPlayingOnly ( nowPlaying ) ] } ) ; } let page = 0 ; const itemsPerPage = 10 ; const pages = _ . chunk ( audioQueue , itemsPerPage ) ; const reactionTime = 120000 ; const embed = createQueueEmbed ( pages [ 0 ] ) ; const embedMessage = await interaction . reply ( { embeds : [ embed ] , fetchReply : true } ) ; if ( pages . length === 1 ) return ; await Promise . all ( [ embedMessage . react ( emoji . leftArrow ) , embedMessage . react ( emoji . rightArrow ) ] ) ; const backwards = embedMessage . createReactionCollector ( { filter : backwardFilter , time : reactionTime , dispose : true , } ) ; const forwards = embedMessage . createReactionCollector ( { filter : forwardFilter , time : reactionTime , dispose : true , } ) ; backwards . on ( 'collect' , backwardHandler ) ; backwards . on ( 'remove' , backwardHandler ) ; forwards . on ( 'collect' , forwardHandler ) ; forwards . on ( 'remove' , forwardHandler ) ; }
Create and send an embed containing details of the current queue.
Create and send an embed containing details of the current queue .
/**
   * Create a queue message embed.
   * @param {import('../../typedefs/audio').Audio[]} pageData - page data to display (up next)
   * @returns {MessageEmbed}
   */ // Format data for up next // Set description (limit 4096 chars, title is 19 chars, 10 songs is approx 1678 chars, footer is 17 chars) // Set description /**
   * Detect if backwards reaction was pressed.
   * @param {MessageReaction} reaction
   * @param {User} user
   * @returns {boolean}
   */ /**
   * Detect if forwards reaction was pressed.
   * @param {MessageReaction} reaction
   * @param {User} user
   * @returns {boolean}
   */ /**
   * Backward button reaction handler.
   * Go back a page in the embed if not at the first page.
   * @param {MessageReaction} reaction
   * @param {User} user
   * @returns {void}
   */ /**
   * Forward button reaction handler.
   * Go forward a page in the embed if not at the last page.
   * @param {MessageReaction} reaction
   * @param {User} user
   * @returns {void}
   */ // If no more songs in queue, send a simple embed only // Initialise // Create and send initial embed // If there is only 1 page do not set up buttons // Reaction collectors // Reaction events