0

您好,非常感谢您访问这个问题:D。
这是我写的一段代码:

for (let i = 0; i < game.channels.length; i++) {
  let channel = msg.guild.channels.cache.find(game.channels[i]); //Line number 249
  msg.guild.channels.cache.get(channel.id).delete();
}
for (let i = 0; i < game.players.length; i++) {
  let member = msg.guild.members.cache.find(game.players[i]);
  console.log(member); //I used this line to see what "member" stored
  msg.guild.members.cache.get(member.id).roles.remove(alive);
}
for (let i = 0; i < game.watchers.length; i++) {
  let member = msg.guild.members.cache.find(game.watchers[i]);
  console.log(member); //I used this line to see what "member" stored
  msg.guild.members.cache.get(member.id).roles.remove(dead);
}
for (let i = 0; i < game.werewolf.length; i++) {
  msg.guild.channels.cache
    .find((c) => c.name == "werewolf-chat" && c.type == "text")
    .permissionOverwrites.get(game.werewolf[i])
    .delete();
}

我的目标是:

  • [在第一个循环中]删除 ID 中定义的频道game.channels
  • [在第二个循环中]aliveID 定义在game.players.
  • [在第三个循环中]alive从ID 中定义的用户中删除名为“Dead”的角色(其 ID 存储为) game.watchers
  • [在第 4 个循环中]删除 ID 中定义的用户的频道权限game.werewolf

但是,以上目标都没有实现;相反,在命令提示符中,出现了:

C:\Users\Admin\node_modules\@discordjs\collection\dist\index.js:160
            if (fn(val, key, this))
                ^

TypeError: fn is not a function
    at Map.find (C:\Users\Admin\node_modules\@discordjs\collection\dist\index.js:160:17)
    at Client.<anonymous> (C:\Users\Admin\Desktop\bot.js:249:56)
    at Client.emit (events.js:310:20)
    at MessageCreateAction.handle (C:\Users\Admin\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Admin\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:\Users\Admin\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31)
    at WebSocketShard.onPacket (C:\Users\Admin\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22)
    at WebSocketShard.onMessage (C:\Users\Admin\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10)
    at WebSocket.onMessage (C:\Users\Admin\node_modules\ws\lib\event-target.js:125:16)
    at WebSocket.emit (events.js:310:20)

期待您的帮助来解决这个问题。再次感谢您的关心。
P/s:我对 Javascript 和 Discord bot 开发非常陌生,所以如果您能尽可能以最清晰和最详细的方式回答这个问题,我将不胜感激。

4

0 回答 0