Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

261
Views
How to send a message in a specific channel with id

I used replit database to save channel id
This is my code:
client.channels.cache.get(db.get(args[1])).send(args[2]);
and i get this error:

client.channels.cache.get(db.get(args[1])).send(args[2]);
                                                ^

TypeError: Cannot read properties of undefined (reading 'send')
    at Client.<anonymous> (/home/runner/anonymesssendbot/index.js:44:49)
    at Client.emit (node:events:390:28)
    at Client.emit (node:domain:475:12)
    at MessageCreateAction.handle (/home/runner/anonymesssendbot/node_modules/discord.js/src/client/actions/MessageCreate.js:34:18)
    at Object.module.exports [as MESSAGE_CREATE] (/home/runner/anonymesssendbot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (/home/runner/anonymesssendbot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:346:31)
    at WebSocketShard.onPacket (/home/runner/anonymesssendbot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:478:22)
    at WebSocketShard.onMessage (/home/runner/anonymesssendbot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:317:10)
    at WebSocket.onMessage (/home/runner/anonymesssendbot/node_modules/ws/lib/event-target.js:199:18)
repl process died unexpectedly: exit status 1
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

I'm guessing that db.get() returns a promise which you cannot pass as a value. Try retrieving the value first and then get the channel. Something like

const id = await db.get(args[1]);
const channel = client.channels.cache.get(id);
channel.send(args[2]);

There is also a possibility that the id is stored incorrectly in your server. So have a look at that. You could log the id to check if that is the case.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!