我收到以下错误:
C:\Users\(private)\discord\bots\(private)\node_modules\@discordjs\collection\dist\index.js:161
if (fn(val, key, this))
^
TypeError: fn is not a function
错误相关代码:
// This is in the discord.js module
find(fn, thisArg) {
if (typeof thisArg !== 'undefined')
fn = fn.bind(thisArg);
for (const [key, val] of this) {
if (fn(val, key, this))
return val;
}
return undefined;
}
如果有帮助,还有我的代码。为了测试目的,我将它简化为一个简单的 console.log:
\\ not everything is here, just the important stuff.
const target = message.guild.members.cache.find(args[0])
console.log(target.roles.forEach(role => console.log(role.id)))
最佳答案
是因为.find()
接受一个函数作为参数,但你提供了一个字符串。它返回给定函数返回真值的第一项。您可以通过检查他们的 id
属性是否与 args[0]
相同来找到成员:
message.guild.members.cache.find((member) => member.id == args[0])
但您可能应该使用 .get()
通过 ID 获取成员的方法更快:
const target = message.guild.members.cache.get(args[0])
关于javascript - Discord 静音命令收到 TypeError : fn is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66164622/