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

150
Views
Unable to send the embeded message in discord.js

I am trying to send an announcement to the channel but I receive this error:

TypeError: Cannot read properties of undefined (reading 'send')

The script:

const Discord = require("discord.js");
const clients = new Discord.Client({ intents: 14087});
const allow = require("./admin/announceAllow.json")
module.exports = {
    name: 'announce',
    description: "announce stuff to announcement server",
    execute(message, args, cmdName, extraString, status, reason,user,id, prefix,lang){
        if(cmdName == ""){
            let err = new Discord.MessageEmbed()
            .setTitle("There was an error while announcing")
            .setDescription("Reason: `Empty string`")
            .setColor("RED")
            message.channel.send({embeds:[err]})
        }else
        if(!(cmdName == "")){
        var toAnnounce = cmdName.replace("announce ","")
        var toSend = "929580453554434089"
        var splitToAnnounce = toAnnounce.split(",,")
        console.log(`${splitToAnnounce[0].replace("|n", "\n")}\n${splitToAnnounce[1].replace("|n", "\n")}\n${splitToAnnounce[2].replace("|n", "\n")}`)
        if(allow[message.author.id + ""]){
            try{
                let announce = new Discord.MessageEmbed()
                .setTitle(`${splitToAnnounce[0].replace("|n", "\n")}`)
                .setDescription(`${splitToAnnounce[1].replace("|n", "\n")}`)
                .setColor(`${splitToAnnounce[2].replace("|n", "\n")}`)
                clients.channels.cache.get(`${toSend}`).send({embeds:[announce]})
            }catch(e){
                let err = new Discord.MessageEmbed()
                .setTitle("There was an error while announcing")
                .setDescription("Possible reason: `Bot don't have permission, bot script outdated, bot error, user input error, color error`\n\nUsage: <prefix> announce `title,,content,,color`\ntip: use `|n` for new line\ncolor: `RED,BLUE,GREEN` etc")
                .setColor("RED")
                message.channel.send({embeds:[err]}) 
                console.log(e)   
            }
        }else
        if(!(allow[message.author.id + ""])){...........

Anyone, please explain why did this error occur and how to fix it

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Have a check on the channel ID in toSend. I have recreated a simply version of this code, and able to get the same error while the channel ID is inputed wrongly. If your command handler is working fine, the problem is mostly come up at the clients.channels.cache.get... part. Above TypeError it should be showing you which line of code is being run as occuring the error.

about 4 years ago · Juan Pablo Isaza 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!