#Message Collector Error

1 messages · Page 1 of 1 (latest)

next prairieBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

potent thicket
#

// @ts-ignore

winged pewter
#
const username_collector = message.channel.createMessageCollector({
  filter,
  max: 1,
  time: 60000,
});

username_collector.on("collect", async (m) => {
  if (m.content.toLowerCase() === "cancel") {
    return username_collector.stop("user cancelled");
  }

  username = m.content;

  username_collector.stop("username collected.");
});

code as actually readable coz gosh those previous lines.

The error is that something is being passed somewhere that is expected to be a string but you're passing undefined.

What that exactly is, is unclear from the given code and error. The error is a shapeshift error so there should be more to it for starters.

winged pewter
potent thicket
#

last I know is that the collector types are f'd and there is no actual solution other than ignoring the typeerror

#

ah no it seems I undid the ignoring at some point this year so the types are fixed, it's most likely your code at fault

winged pewter
#

Granted this is Sapphire, I get no type errors here:

public override async messageRun(message: Message) {
  const username_collector = message.channel.createMessageCollector({
    filter: (msg) => msg.author.id === message.author.id,
    max: 1,
    time: 60000
  });

  let username: string | undefined;

  username_collector.on('collect', async (m) => {
    if (m.content.toLowerCase() === 'cancel') {
      return username_collector.stop('user cancelled');
    }

    username = m.content;

    username_collector.stop('username collected.');
  });
}
#

And the only "sapphire" part of that is the method being called messageRun

potent thicket
#

generally I'd say avoid the event based collectors and use the promise based ones

#

a lot cleaner

winged pewter
#

by using channel.awaitMessages instead

potent thicket
#

your're welcome 1000kg

winged pewter
#
public override async messageRun(message: Message) {
  const collector = await message.channel.awaitMessages({
    filter: (msg) => msg.author.id === message.author.id,
    max: 1,
    time: 60000
  });
  const response = collector.first();

  if (!response) {
    throw new Error('No messages received');
  }

  const username = response.content;
}
#

Alternatively you can also use our package which has a MessagePrompter class

heavy questBOT
#

Discord.js specific utilities for your JavaScript/TypeScript bots

❯ Author: sapphiredev
❯ Maintainers: favna, kyranet, and vladfrangu
❯ Latest version: 6.0.4
❯ License: MIT
❯ Date Created: <t:1609519287:d>
❯ Date Modified: <t:1679877565:d>

Dependencies:
@sapphire/discord-utilities, @sapphire/duration, @sapphire/utilities, and tslib

winged pewter
stuck frost
#

I'm more interested in that formatted error

did you do it manually or used some logger lib? 🤔

undone meteor