Message Collector Error

I'm creating a message collector like this - however after it runs and collects m.content and sets it to username, which I can log into the console just fine - I receive the following error preventing further code run. Also getting a shit ton of type errors. OG Code
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.')
})
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.')
})
Error
Error (1)
Received one or more errors

input[0]
| CombinedPropertyError (1)
| Received one or more errors
|
| input.value
| | ValidationError > s.string
| | Expected a string primitive
| |
| | Received:
| | | undefined
Error (1)
Received one or more errors

input[0]
| CombinedPropertyError (1)
| Received one or more errors
|
| input.value
| | ValidationError > s.string
| | Expected a string primitive
| |
| | Received:
| | | undefined
18 Replies
adrian
adrian12mo ago
// @ts-ignore
Favna
Favna12mo ago
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.");
});
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.
adrian
adrian12mo ago
last I know is that the collector types are f'd and there is no actual solution other than ignoring the typeerror
riskiscool
riskiscool12mo ago
they have to be fucked up because im not passing in any weird arguments im just typing in the expected string message in chat and I can log it just fine but yeah I'd rather not just ignore it
adrian
adrian12mo ago
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
Favna
Favna12mo ago
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.');
});
}
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
riskiscool
riskiscool12mo ago
I have one more question What's the best way to continue my code after I collect the max filter amount without needing to continue writing my code inside the .on('end' function or something like is there a linear way I can continue without nesting code too much
adrian
adrian12mo ago
generally I'd say avoid the event based collectors and use the promise based ones a lot cleaner
riskiscool
riskiscool12mo ago
Okat let me switch to that
Favna
Favna12mo ago
by using channel.awaitMessages instead
riskiscool
riskiscool12mo ago
Yeah its so much cleaner thanks a ton
adrian
adrian12mo ago
your're welcome 1000kg
Favna
Favna12mo ago
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;
}
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
Spinel
Spinel12mo ago
@sapphire/discord.js-utilities
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
MRDGH2821
MRDGH282112mo ago
I'm more interested in that formatted error did you do it manually or used some logger lib? 🤔
KaydaFox
KaydaFox12mo ago
thats just how @sapphire/shapeshit logs its errors i think, so you could find it in the code for that
MRDGH2821
MRDGH282112mo ago
I see 🤔
Want results from more Discord servers?
Add your server
More Posts