#Error when sending message

39 messages · Page 1 of 1 (latest)

ornate remnant
#
    const channel = client.channels.cache.get('906674895239405678');
    channel.send('content');

Wanting to send this basic message to a channel, but this error is produced: Cannot read properties of undefined (reading 'send'). Please shed some light on this 🙂

wise idol
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

ornate remnant
#

v16.16.0

grizzled hull
#

The id is invalid

ornate remnant
raven raptor
#

Not necessarily

#

Is the client logged in and do you have Guilds intent

#

Well GUILDS as this is v13

ornate remnant
#
const client = new Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MEMBERS,
    Intents.FLAGS.GUILD_BANS,
    Intents.FLAGS.GUILD_INTEGRATIONS,
    Intents.FLAGS.GUILD_WEBHOOKS,
    Intents.FLAGS.GUILD_INVITES,
    Intents.FLAGS.GUILD_VOICE_STATES,
    Intents.FLAGS.GUILD_PRESENCES,
    Intents.FLAGS.GUILD_MESSAGES,
    Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
    Intents.FLAGS.GUILD_MESSAGE_TYPING,
    Intents.FLAGS.DIRECT_MESSAGES,
    Intents.FLAGS.DIRECT_MESSAGE_REACTIONS,
    Intents.FLAGS.DIRECT_MESSAGE_TYPING,
  ],
}); //Create client
#

These are my intents

grizzled hull
#

Is the client logged in

ornate remnant
#

client.login(token);

raven raptor
#

And log what it says

#

And show us

ornate remnant
#
client.once("ready", () => {
  
    const channel = client.channels.cache.get('906674895239405678');
    channel.send('content');

this?

raven raptor
#

if the code is running inside your ready event then yes, the id is likely incorrect

ornate remnant
#

but it cant be?

grizzled hull
#

uh yes it can

raven raptor
#

Well it can be if your ready event is emitting

ornate remnant
raven raptor
#

If you really wanna check

#

const channel = await client.channels.fetch(<id>)

#

And see if it throws an error

ornate remnant
raven raptor
#

Then your bot doesn’t have access to that channel

ornate remnant
#

It has administrator perms?

raven raptor
#

Idk does it?

grizzled hull
#

Are you sure?

ornate remnant
#

Yep

raven raptor
#

Well it doesn’t lol

ornate remnant
raven raptor
#

Definitely the correct id?

#

Check again

ornate remnant
#

Just checked, defo the right ID

raven raptor
#

Then you either don’t have the correct permissions or the id is still wrong

ornate remnant
#

It don’t think it is, but i’ll search around for a solution