I have a basic command for testing the message collector feature on my discord.js v13 bot.
The bot doesn’t crash when I run it, but the feature doesn’t load properly, as it has an error.
JavaScript
x
42
42
1
import { ICommand } from 'wokcommands'
2
import { Message } from 'discord.js'
3
4
export default {
5
category: 'Testing',
6
description: 'Tests the collector system',
7
hidden: true,
8
9
callback: ({ message, channel }) => {
10
message.reply('Answer your username')
11
12
const filter = (m: Message) => {
13
m.author.id === message.author.id
14
}
15
16
const collector = channel.createMessageCollector({
17
filter,
18
max: 1,
19
time: 1000 * 10,
20
})
21
22
collector.on('collect', message => {
23
console.log(message.content)
24
})
25
26
collector.on('end', collected => {
27
if (collected.size === 0) {
28
message.reply('You did not provide your username')
29
return
30
}
31
32
let text = 'Collected:nn'
33
34
collected.forEach((message) => {
35
text += `${message.content}n`
36
})
37
38
message.reply(text)
39
})
40
}
41
} as ICommand
42
The error is in the line inside the collector function when I call filter. The IDE gives me an error:
Type ‘(m: Message) => void’ is not assignable to type ‘CollectorFilter<[Message]>’. Type ‘void’ is not assignable to type ‘boolean | Promise’.
I understand what the error is trying to say, but how can I fix it?
Advertisement
Answer
Your filter
needs to return a boolean. At the moment you don’t return anything, you just compare the two variables. Any of these will work:
JavaScript
1
4
1
const filter = (m: Message) => {
2
return m.author.id === message.author.id
3
}
4
JavaScript
1
2
1
const filter = (m: Message) => m.author.id === message.author.id
2