Skip to content
Advertisement

Message collector in Discord.JS not running

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.

import { ICommand } from 'wokcommands'
import { Message } from 'discord.js'

export default {
    category: 'Testing',
    description: 'Tests the collector system',
    hidden: true,

    callback: ({ message, channel }) => {
        message.reply('Answer your username')

        const filter = (m: Message) => {
            m.author.id === message.author.id
        }

        const collector = channel.createMessageCollector({
            filter,
            max: 1,
            time: 1000 * 10,
        })

        collector.on('collect', message => {
            console.log(message.content)
        })
        
        collector.on('end', collected => {
            if (collected.size === 0) {
                message.reply('You did not provide your username')
                return
            }

            let text = 'Collected:nn'

            collected.forEach((message) => {
                text += `${message.content}n`
            })

            message.reply(text)
        })
    }
} as ICommand

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:

const filter = (m: Message) => {
  return m.author.id === message.author.id
}
const filter = (m: Message) => m.author.id === message.author.id
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement