So I've recently gained the courage to update to the latest discord API from v11 to v12 and I'm now getting type errors on my commands.
TypeError: fn.bind is not a function
I also updated discord commando to the latest build for v12.
I'll post the whole code here just in case I've done something wrong anywhere.
This is my first time updating code so I'm unsure of what I have done wrong any ideas or pointers would be appreciated :)
const commando = require('discord.js-commando')
module.exports = class lycanattack extends commando.Command {
constructor(client) {
super(client, {
name: 'lycanattack',
aliases: ['lycana', 'lycanatt'],
group: 'roleplay',
memberName: 'lycanattack',
description: 'use your Lycan(werewolve) form to attack someone once a week for a chance to infect them on use **Lycan restricted** :wolf:',
throttling: {
usages: 1,
duration: 604800,
},
});
}
async run(message, user, args) {
if (message.member.roles.cache.find("name", "Lycan")) {
const lycanRole = message.guild.roles.cache.find(role => role.name === 'Lycan');
let member = message.mentions.members.first();
var lycanroll = Math.floor(Math.random() * 100) + 1;
if (lycanroll < 30)
member.roles.add(lycanRole),
message.reply(`*goes on the hunt to find* ${member} you find them near hogsmead and infect them with your **Lycan curse** \n ${member} is now a **Lycan** :wolf: :full_moon:`)
else if (lycanroll < 40)
message.reply(` ${member} was nearly attacked but they managed to escape back to hogwarts maybe ${member} shouldn't sneak out so often.`);
else
message.reply(`you go on the hunt for ${member} but they are protected by the walls of hogwarts maybe next moon. :full_moon:`);
} else {
message.reply("You are not Lycan")
}
}
}
Error:
Error in command house:slytherinmotto TypeError: fn.bind is not a function
at Map.find (C:\Users\user\Desktop\HogwartsBot\node_modules\@discordjs\collection\dist\index.js:158:21)
at slytherinmotto.run (C:\Users\user\Desktop\HogwartsBot\commands\house\slytherin.js:18:35)
at CommandoMessage.run (C:\Users\user\Desktop\HogwartsBot\node_modules\discord.js-commando\src\extensions\message.js:222:34)
at CommandDispatcher.handleMessage (C:\Users\user\Desktop\HogwartsBot\node_modules\discord.js-commando\src\dispatcher.js:143:32) at CommandoClient.<anonymous> (C:\Users\user\Desktop\HogwartsBot\node_modules\discord.js-commando\src\client.js:64:51)
at CommandoClient.emit (events.js:215:7)
at MessageCreateAction.handle (C:\Users\user\Desktop\HogwartsBot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\user\Desktop\HogwartsBot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\user\Desktop\HogwartsBot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31)
at WebSocketShard.onPacket (C:\Users\user\Desktop\HogwartsBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22)
```
What you are doing wrong is the part where you search for the role by its name:
replace message.member.roles.cache.find("name", "Lycan")
with message.member.roles.cache.find(role => role.name === "Lycan")
(https://discord.js.org/#/docs/collection/master/class/Collection?scrollTo=find)