0

所以我最近鼓起勇气将最新的不和谐 API 从 v11 更新到 v12,现在我的命令出现类型错误。

TypeError: fn.bind is not a function

我还将不和谐突击队更新为 v12 的最新版本。

我会在这里发布整个代码,以防万一我在任何地方做错了什么。

这是我第一次更新代码,所以我不确定我做错了什么任何想法或指针将不胜感激:)

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 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)
    ```
4

1 回答 1

1

您做错的是您按名称搜索角色的部分:

代替message.member.roles.cache.find("name", "Lycan")

message.member.roles.cache.find(role => role.name === "Lycan")

https://discord.js.org/#/docs/collection/master/class/Collection?scrollTo=find

于 2020-06-19T16:42:07.570 回答