Cannot read properties of undefined error when modularizing commands

Viewed 19

There is a problem that commands such as "await client.channels.cache.get('1020656369021489182').send('dd')" cannot be used when used in a command modular manner. It works well when it is not modular, but it enters the module and does not operate commands in individual files. I ask for your help on how to solve this problem!

The following error occurs when you execute the command

TypeError: Cannot read properties of undefined (reading 'send')
    at Object.execute (C:\discordbot\music\commands\ping.js:10:57)
    at Client.<anonymous> (C:\discordbot\music\reindex.js:32:17)
    at Client.emit (node:events:527:28)
    at InteractionCreateAction.handle (C:\discordbot\music\node_modules\discord.js\src\client\actions\InteractionCreate.js:81:12)
    at Object.module.exports [as INTERACTION_CREATE] (C:\discordbot\music\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
    at WebSocketManager.handlePacket (C:\discordbot\music\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
    at WebSocketShard.onPacket (C:\discordbot\music\node_modules\discord.js\src\client\websocket\WebSocketShard.js:481:22)
    at WebSocketShard.onMessage (C:\discordbot\music\node_modules\discord.js\src\client\websocket\WebSocketShard.js:321:10)
    at WebSocket.onMessage (C:\discordbot\music\node_modules\ws\lib\event-target.js:199:18)
    at WebSocket.emit (node:events:527:28)
1 Answers

Seems like 1020656369021489182 is not a valid channel id or that channel doesn't exist.

Related