#What error are you getting

1 messages · Page 1 of 1 (latest)

weak wharf
#
        sendChannel.send({ embeds: [embed] })
                    ^
TypeError: Cannot read properties of undefined (reading 'send')
    at Object.run (H:\dev\kubib bot js v2\src\commands\announce.command.js:36:21)
    at Client.<anonymous> (H:\dev\kubib bot js v2\src\handlers\command.handler.js:197:25)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
#
        sendChannel.send({ embeds: [embed] })```
tulip fulcrum
#

Is this in an event listener?

weak wharf
#

no

#

thats a command which is intended to send an announcement (message) to a specific channelk

#

when i use channel.send it does not happen

finite swallow
#

i don't want to be rude, but are you defining announcementChannelID correctly? if you log it to console, does it record the channel id?

weak wharf
#

no problem

#

989487197881270383
H:\dev\kubib bot js v2\src\commands\announce.command.js:37
sendChannel.send({ embeds: [embed] })
^

TypeError: Cannot read properties of undefined (reading 'send')
at Object.run (H:\dev\kubib bot js v2\src\commands\announce.command.js:37:21)
at Client.<anonymous> (H:\dev\kubib bot js v2\src\handlers\command.handler.js:197:25)
at processTicksAndRejections (node:internal/process/task_queues:96:5)

#

logs it properly

pulsar quest
weak wharf
#

yes

#

thats a coomand

finite swallow
#

syntax is completely correct, channel id is known to be an actual channel id (i think, right?)

pulsar quest
#

Wait, is it a string or a number

weak wharf
#

string, from js

#

json

pulsar quest
#

Show the definition

weak wharf
#

i think that might be an issue

pulsar quest
#

Nah thats ok

weak wharf
#

then

#

const { announcementChannelID } = require("./../config/config.json")

pulsar quest
#

Do you have the GUILDS intent

weak wharf
tulip fulcrum
#

Log client.isReady() right after the line where you define sendChannel, please

weak wharf
#

false
H:\dev\kubib bot js v2\src\commands\announce.command.js:34
sendChannel.send({ embeds: [embed] })
^

TypeError: Cannot read properties of undefined (reading 'send')
at Object.run (H:\dev\kubib bot js v2\src\commands\announce.command.js:34:21)
at Client.<anonymous> (H:\dev\kubib bot js v2\src\handlers\command.handler.js:197:25)
at processTicksAndRejections (node:internal/process/task_queues:96:5)

#

it is not

#

but it happens only when i run this command with args

#

the client is not ready

pulsar quest
weak wharf
#

this code is called within a command file

tulip fulcrum
#

How is that command triggering if your client isn't ready?

weak wharf
#
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILDS]})
const { announcementChannelID } = require("./../config/config.json")
const {link} = require("fs");

module.exports = {
    name: "announce",
    description: "Sends an announcement message",
    usage: '<link> <message>',
    args: true,
    botPermissions: [Permissions.FLAGS.ADMINISTRATOR],
    userPermissions: [Permissions.FLAGS.ADMINISTRATOR],
    guildOnly: true,

    async run(msg, args) {
        const { channel, guild, mentions, author } = msg

        const msgArg = [...args].slice(0).join(" ")

        const embed = new MessageEmbed()
            .setTitle('Ogłoszenie')
            .addFields({
                name: 'Treść',
                value: `${msgArg}`,
        })
            .setColor('3b86ff')
            .setTimestamp(Date.now())
            .setFooter({text: "test", iconURL: "https://static.wikia.nocookie.net/logopedia/images/1/1e/Windows_Logo_1995.svg/revision/latest/scale-to-width-down/200?cb=20210627140311"})

        //console.log(announcementChannelID)
        //const sendChannel = await channels.fetch(announcementChannelID)
        const sendChannel = client.channels.cache.get(announcementChannelID)
        console.log(client.isReady())
        sendChannel.send({ embeds: [embed] })


    }
}```
#

thats my whole command file

#

and it is triggered by a command handler

pulsar quest
#

Boi

#

You cant create a new client instant here

#

Use msg.client instead

weak wharf
#

ok thank you!

#

wait

#

where

#

the new client

#

in the command i guess

pulsar quest
#

At the top ??

weak wharf
#

what about the intents then?

pulsar quest
#

That's all supposed to be in your main client definition