discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.39k stars 3.97k forks source link

TypeError: fn is not a function #5393

Closed GroovyGab closed 3 years ago

GroovyGab commented 3 years ago

Please describe the problem you are having in as much detail as possible: TypeError: fn is not a function when obtaining a role from a guild.

Include a reproducible code sample here, if possible:

        const role = mentions.roles.first()
          ? mentions.roles.first().id
          : cmdArgs[1]; // cmdArgs[1] as a role id string.

        const fetchedRole = guild.roles.cache.find(role);

Gives this error:

Error in command moderation:ban TypeError: fn is not a function
    at Map.find (/home/ubuntu/Zora/node_modules/@discordjs/collection/dist/index.js:161:17)
    at BanCommand.run (/home/ubuntu/Zora/commands/moderation/ban.js:41:47)
    at CommandoMessage.run (/home/ubuntu/Zora/node_modules/discord.js-commando/src/extensions/message.js:222:34)
    at CommandDispatcher.handleMessage (/home/ubuntu/Zora/node_modules/discord.js-commando/src/dispatcher.js:144:32)
    at ZoraClient.<anonymous> (/home/ubuntu/Zora/node_modules/discord.js-commando/src/client.js:64:51)
    at ZoraClient.emit (node:events:378:20)
    at MessageCreateAction.handle (/home/ubuntu/Zora/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (/home/ubuntu/Zora/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (/home/ubuntu/Zora/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (/home/ubuntu/Zora/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (/home/ubuntu/Zora/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
    at WebSocket.onMessage (/home/ubuntu/Zora/node_modules/ws/lib/event-target.js:132:16)
    at WebSocket.emit (node:events:378:20)
    at Receiver.receiverOnMessage (/home/ubuntu/Zora/node_modules/ws/lib/websocket.js:825:20)
    at Receiver.emit (node:events:378:20)
    at Receiver.dataMessage (/home/ubuntu/Zora/node_modules/ws/lib/receiver.js:437:14)

Further details:

Relevant client options:

anandre commented 3 years ago

Collection#find accepts a function, which you do not provide. Please refer to the docs

GroovyGab commented 3 years ago

Collection#find accepts a function, which you do not provide. Please refer to the docs

Lol sorry, my bad.