'channel id not recognised in discordjs

I'm trying to connect to the second channel of the server but it seems like it doesnt exist throwin an error when executing :

 /home/ser356/Escritorio/node discord/app.js:11
        channel.send("ola");
                ^
    
    TypeError: Cannot read properties of undefined (reading 'send')


/*/*/*/*/*/*/*/
    

const {Client,Intents} = require("discord.js");
    require('dotenv').config();
    
    const client = new Client({intents: [Intents.FLAGS.GUILDS]});
    
    client.login(process.env.BOT_TOKEN);
    
    
       
        const channel =  client.channels.cache.get('950537341280325632')
        channel.send("hola");

I don't know what i'm doing wrongg because i've copied exactly the id from discord.

Edit: i add the .env file too

BOT_TOKEN="OTUwNTQyNDQ5MzYzODA4MzA2.YiabpA.bulmNmwGgz9s8kOPyvjngR_rSbo"

Update

Solved adding an event before logging in:

const {Client,Intents} = require("discord.js");
require('dotenv').config();
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_>
var arguments=process.argv[2];
console.log(arguments)
//client.login("OTUwNTQyNDQ5MzYzODA4MzA2.YiabpA.bulmNmwGgz9s8kOPyvjngR_rSbo");
client.on('ready', () => {
var canal =  client.channels.cache.get("950644612517724171")
if(arguments==='start'){
canal.send("klk")
}
else if(arguments==='stop'){
canal.send("klwa")
}
else{
canal.send("nada")
}
});

client.login(process.env.BOT_TOKEN)


Solution 1:[1]

Since you're using client,

client.on('messageCreate', message => {
      if(message.author.bot) return;
      const channel = client.channels.cache.find(channel => channel.id === "950537341280325632")
      return channel.send("Testing for stackoverflow").catch((err) => console.log(err))
    })

Take note that every chat you'll do your bot will send again.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1