Type error: fn is not a function. I don't know how to fix that.. Any help? (VSC)

Hello. I’d like to ask for help/advice. I’ve been trying to code a Discord bot to do a Timed mute, but there seems to be an error which I don’t know how to fix.

The error:

if (fn(val, key, this))

TypeError: fn is not a function

Here is my coding:

switch (args[0]) {
case ‘mute’:

            let person = message.guild.roles.cache.find(message.mentions.users.first() || message.guild.roles.cache.find(args[1]))

            if (!person) return message.reply("Person does not exist/Couldn't find member");

            let mainrole = message.guild.roles.find(role => role.name === "Berries");

            let muterole = message.guild.roles.find(role => role.name === "Muted D:");

            if (!muterole) return message.reply("Unable to find muterole");

            let time = args[2];

            if (!time) {

                return message.reply("Time not specified");




            message.channel.send(`@${person.user.tag} has been muted for ${ms(ms(time))}`);

            setTimeout(function () {



                message.channel.send(`@${person.user.tag} has been unmuted!`)

            }, ms(time));


I’m a begginer actually, and I don’t know what’s wrong with my coding. I would very appreciate any kind of help or explanation! :slight_smile:

It looks like you haven’t declared fn() anywhere.

Yes, that is what confuses me. I did not declare fn or anything that the error says. I don’t know if I should declare it, or how do I fix it?

The error message should tell you on what line of which file the error is.

TypeError: fn is not a function
at Map.find (C:\Users\CFY\Desktop\Disc bot2\node_modules@discordjs\collection\dist\index.js:160:17)
at Client. (C:\Users\CFY\Desktop\Disc bot2\index.js:74:121)
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (C:\Users\CFY\Desktop\Disc bot2\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\CFY\Desktop\Disc bot2\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\CFY\Desktop\Disc bot2\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31)
at WebSocketShard.onPacket (C:\Users\CFY\Desktop\Disc bot2\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22)
at WebSocketShard.onMessage (C:\Users\CFY\Desktop\Disc bot2\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10)
at WebSocket.onMessage (C:\Users\CFY\Desktop\Disc bot2\node_modules\ws\lib\event-target.js:125:16)
at WebSocket.emit (events.js:315:20)

Looks like the discordjs module that you are using is probably expecting you to implement something in a particular way that you aren’t.