我遇到以下错误:
TypeError: fn is not a function -
at Map.find (c:\Users\soric\Desktop\Discord Bot\node_modules\@discordjs\collection\dist\index.js:160:17) -
at Client.<anonymous> (c:\Users\soric\Desktop\Discord Bot\index.js:162:111) -
at Client.emit (events.js:322:22) -
at MessageCreateAction.handle (c:\Users\soric\Desktop\Discord Bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14) -
at Object.module.exports [as MESSAGE_CREATE] (c:\Users\soric\Desktop\Discord Bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
代码:
case 'mute':
if (!message.member.hasPermission('ADMINISTRATOR')) return message.channel.send(" You don't the permission for that!");
let person = message.guild.member(message.mentions.users.first() || message.guild.roles.cache.find(args[1]))
if (!person) return message.reply("Player not found, he's hiding somewhere!");
let mainrole = message.guild.roles.find(role => role.name === "Gangster");
let muterole = message.guild.roles.find(role => role.name === "Muted");
if (!muterole) return message.reply("Couldn't find the mute role!");
let time = args[2];
if (!time) {
return message.reply("You didn't specify a time!");
}
person.removeRole(mainrole.id);
person.addRole(muterole.id);
message.channel.send(`@${person.user.tag} has now been muted for ${ms(ms(time))} `);
setTimeout(function () {
person.addRole(mainrole.id);
person.removeRole(muterole.id);
message.channel.send(`@${person.user.tag} has been unmuted!`)
}, ms(time));
break;
答案 0 :(得分:0)
message.guild.roles.cache.find(args[1]))
在您向我们展示的代码的第3行上
.find
方法始终使用函数,而不是字符串。我假设您应该使用.get
而不是.find
。
希望我能帮上忙!