Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

javascript - When I run a script it tells me that filter is not a function. [Discord.js]

I have a script where you need to answer to the bot with yes (da in the script) or no (nu in the script) and when I run the script on discord it tells me that filter is not a function. I have to mention that I am a beginner.

The script is this:

module.exports = {
name: 'moneda',
description: 'mai usor de luat o decizie',
execute(message, args){
    let decizii = [
        "Fata",
        "Spate",
    ]
    let decizie = decizii[Math.floor(Math.random() * (decizii.length))]
    message.reply(`Ti-a picat ${decizie}`);
    let decizii1 = [
        "Fata",
        "Spate",
    ]
    let decizie1 = decizii1[Math.floor(Math.random() * (decizii1.length))]
    message.channel.send('Mai vrei sa incerci odata?').then(async (start) => {
        message.channel.awaitMessage(filter, { maxMatches: 1, time: 60000, errors: ['time']}).then(async (collected) => {
            if(collected.first().content === 'da') {message.channel.send(decizie1)} else if (collected.first().content === 'nu') {return}
        })
    })
}
}

The error is this:

(node:8340) UnhandledPromiseRejectionWarning: ReferenceError: filter is not defined
at C:UsersADRIANDesktoperOne BOTcommandsmoneda.js:18:42
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:8340) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated 
either by throwing inside of an async function without a catch block, or by rejecting a promise which 
was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the 
CLI flag `--unhandled-rejections=strict` (see 
https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:8340) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, 
promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

filter is not defined, means that you have to create a filter.

This is an example filter, for your problem:

let filter = m => m.author.id === message.author.id;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...