Discord.js v12 类型错误突击队
Posted
技术标签:
【中文标题】Discord.js v12 类型错误突击队【英文标题】:Discord.js v12 type errors commando 【发布时间】:2020-10-09 22:42:48 【问题描述】:所以我最近鼓起勇气将最新的 discord API 从 v11 更新到 v12,但现在我的命令出现类型错误。
TypeError: fn.bind is not a function
我还将 discord commando 更新到 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)
```
【问题讨论】:
【参考方案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)
【讨论】:
啊,我明白了,谢谢,我认为问题可能出在突击队本身上 我看到你在下一行做对了,你只是忘了在那里做以上是关于Discord.js v12 类型错误突击队的主要内容,如果未能解决你的问题,请参考以下文章