#Message Collector Error
1 messages · Page 1 of 1 (latest)
// @ts-ignore
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.
Please only contribute actual solutions in the help channels and not hacky workarounds.
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
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
generally I'd say avoid the event based collectors and use the promise based ones
a lot cleaner
by using channel.awaitMessages instead
your're welcome 1000kg
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
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
I'm more interested in that formatted error
did you do it manually or used some logger lib? 🤔
thats just how @sapphire/shapeshit logs its errors i think, so you could find it in the code for that