Hello there and thank you so much for your visit to the question :D.
Here is a piece of code I've written:

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();
}

My goals are to:

  • [In the 1st loop] Delete channels with their IDs defined in game.channels.
  • [In the 2nd loop] Remove a role named "Alive" (which has its ID store as alive) from users with their IDs defined in game.players.
  • [In the 3rd loop] Remove a role named "Dead" (which has its ID store as alive) from users with their IDs defined in game.watchers.
  • [In the 4th loop] Delete a channel's permissions for users with their IDs defined in game.werewolf.

However, none of the goals above is achieved; instead, in the Command Prompt, this appeared:

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)

Looking forward to your help to fix this problem. Once again, thank you for your caring.
P/s: I'm very new to Javascript and Discord bot developing, so I'm highly grateful if you can answer this question in the clearest and most detailed as you possibly can.

0

There are 0 best solutions below