0
votes
case 'mute':
            var person  = message.guild.member(message.mentions.users.first() || message.guild.roles.cache.find()(args[1]));
            if(!person) return message.reply("That player doesn't exist!");

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

            if(!muterole) return message.reply("Couldn't find the mute role.");

            let time = args[2];

            if(!time){
                return message.reply("Please didnt specify a time!");
            }

            person.roles.add(mainrole.id)
            person.roles.remove(role.id);

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

                person.roles.add(mainrole.id)
                person.roles.remove(role.id);
                console.log(role.id)
                message.channel.send(`@${person.user.tag} has been unmuted!`)
            }, ms(time));
            break;
        }
}); 

is my code.

TypeError: fn is not a function at Client. (C:\Users\nippo\Desktop\aniGuesser\index.js:64:112) at Client.emit (events.js:327:22) at MessageCreateAction.handle (C:\Users\nippo\Desktop\aniGuesser\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14) at Object.module.exports [as MESSAGE_CREATE] (C:\Users\nippo\Desktop\aniGuesser\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32) at WebSocketManager.handlePacket (C:\Users\nippo\Desktop\aniGuesser\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31) at WebSocketShard.onPacket (C:\Users\nippo\Desktop\aniGuesser\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22) at WebSocketShard.onMessage (C:\Users\nippo\Desktop\aniGuesser\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10) at WebSocket.onMessage (C:\Users\nippo\Desktop\aniGuesser\node_modules\ws\lib\event-target.js:125:16) at WebSocket.emit (events.js:315:20) PS C:\Users\nippo\Desktop\aniGuesser> node . aniGuesser Is Online. Bring the Cake! C:\Users\nippo\Desktop\aniGuesser\node_modules@discordjs\collection\dist\index.js:160 if (fn(val, key, this)) the error thingy.

I decided to start making a bot so my friends think im smart so i started watching a youtube series on how to configure these bots. In the process i decided to make a mute command cuz why not but then i got this error. before this i had "message.guild.roles.get" and the comments told me to change it to message.guild.roles.cache.find although that resolved my problem, i have this error now. btw even when i use the paste bin and only changing the words around it still has this error.

1
From the stack trace (the errors), it looks like on line 64 of your code you have a function called fn that wasn't defined before. What does that look like?Montgomery Watts
i dont understand what u mean by, a function called fn. I dont know if that means much but the only line changed was the ; at the of line 64, which did absolutely nothing.lovebeensippin
It seems like you're calling something called fn as if it were a function. That would look something like this fn(), similar to what you're doing when you call console.log(). The problem is coming from you calling fn without it actually being a function. Is fn defined earlier in your code?Montgomery Watts
When i get rid of .find and replace it with .get it says this: pastebin.com/tJh4Us0Ylovebeensippin
Could you please edit your question to include line 64? The code you have provided does not show where the error or fn came from.cherryblossom

1 Answers

0
votes

Your problem is this: message.guild.roles.cache.find()(args[1]));.

First, find takes a function, (which causes the error shown).

Second, you're trying to call the value returned by find which would be a role and not a function find()(args[1]), but I assume this was a typo and you meant to use this to add a function.