#What error are you getting
1 messages · Page 1 of 1 (latest)
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] })```
Is this in an event listener?
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
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?
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
Where do you execute the code, is the client ready when that executes?
syntax is completely correct, channel id is known to be an actual channel id (i think, right?)
Wait, is it a string or a number
Show the definition
Nah thats ok
Do you have the GUILDS intent
Log client.isReady() right after the line where you define sendChannel, please
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
Where is the function with that code being called
this code is called within a command file
How is that command triggering if your client isn't ready?
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
At the top ??
what about the intents then?
That's all supposed to be in your main client definition