错误 "fn不是一个函数"(discord.js机器人)。

问题描述 投票:0回答:1

我得到以下错误信息。

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;
discord.js
1个回答
0
投票

message.guild.roles.cache.find(args[1])) 在你给我们看的那段代码的第3行中

.find 方法总是接受一个函数,而不是一个字符串。我想你应该是用 .get 而不是 .find.

希望我可以帮助你

© www.soinside.com 2019 - 2024. All rights reserved.