Collectors

Wait for a reply or reaction with awaitMessages / awaitReactions.

Short path: wait once, then continue. Use this for confirmations and polls.

Collectors require time and/or max. Omitting both throws FluxerError with ErrorCodes.CollectorOptionsRequired.

By default, awaitMessages / awaitReactions reject when the collector ends for time (CollectorIdle) or max / limit (CollectorMax). Pass errors: ['time'] if you want a successful resolve when max is hit (only idle rejects). Pass errors: [] to always resolve with the collection.

awaitMessages

javascript
import { FluxerError, ErrorCodes } from '@fluxerjs/core';

const channel = message.channel ?? (await message.resolveChannel());
await message.reply('What is your favorite color? (15s)');

try {
  const collected = await channel.awaitMessages({
    filter: (m) => m.author.id === message.author.id,
    max: 1,
    time: 15_000,
    errors: ['time'], // resolve when max is hit; reject only on idle
  });
  const answer = collected.first();
  if (answer) await answer.reply(`Nice. You said: ${answer.content}`);
} catch (err) {
  if (err instanceof FluxerError && err.code === ErrorCodes.CollectorIdle) {
    await message.reply('Timed out.');
    return;
  }
  throw err;
}

awaitReactions

javascript
import { FluxerError, ErrorCodes } from '@fluxerjs/core';

const prompt = await message.reply('React πŸ‘ or πŸ‘Ž (30s)');
await prompt.react('πŸ‘');
await prompt.react('πŸ‘Ž');

try {
  const collected = await prompt.awaitReactions({
    // Collector filter is (reaction, user). Gateway MessageReactionAdd is one payload object.
    filter: (reaction, user) =>
      !user.bot && (reaction.emoji.name === 'πŸ‘' || reaction.emoji.name === 'πŸ‘Ž'),
    max: 1,
    time: 30_000,
    errors: ['time'],
  });
  const hit = collected.first();
  if (hit) await prompt.reply(`Picked ${hit.emoji.name}`);
} catch (err) {
  if (err instanceof FluxerError && err.code === ErrorCodes.CollectorIdle) {
    await prompt.reply('No vote.');
  }
}

Advanced: EventEmitter collectors

createMessageCollector / createReactionCollector if you need collect / end events, stop(), or to keep the collector around.

javascript
const collector = channel.createMessageCollector({
  filter: (m) => m.author.id === message.author.id,
  time: 15_000,
  max: 1,
});

collector.on('collect', async (m) => {
  await m.reply(`Got it: ${m.content}`);
});

collector.on('end', (collected, reason) => {
  console.log(`Stopped (${reason}) with ${collected.size} message(s)`);
});

For long-lived reaction roles, use a permanent Events.MessageReactionAdd listener instead of a short collector. See reaction-roles-bot.

Questions?Join the Fluxer community for help with the SDK.Join Fluxer