Send a message in a specific channel?

I copy pasted the guide and it doesn't work. Maybe there are some errors?
import { Client, Events, GatewayIntentBits, Partials } from "discord.js"
...
const channel = client.channels.cache.get("1274810907113029664");
const timePassed = 0

setInterval(() => {
channel.send(`${timePassed} minutes has passed`);
timePassed++
}, 1 * 60 * 1000);
import { Client, Events, GatewayIntentBits, Partials } from "discord.js"
...
const channel = client.channels.cache.get("1274810907113029664");
const timePassed = 0

setInterval(() => {
channel.send(`${timePassed} minutes has passed`);
timePassed++
}, 1 * 60 * 1000);
channel.send(`${timePassed} minutes has passed`);
^

TypeError: Cannot read properties of undefined (reading 'send')
at file:///C:/Users/zxc/Documents/Coding%20Projects/admiral%20hipper/main.js:44:9
at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5)
channel.send(`${timePassed} minutes has passed`);
^

TypeError: Cannot read properties of undefined (reading 'send')
at file:///C:/Users/zxc/Documents/Coding%20Projects/admiral%20hipper/main.js:44:9
at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5)
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
4 Replies
d.js toolkit
d.js toolkit4mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
medi
mediOP4mo ago
@Qjuh
treble/luna
treble/luna4mo ago
do you have the Guilds intent
medi
mediOP4mo ago
here are my intents
const client = new Client ({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
],
partials: [
Partials.Channel
],
})
const client = new Client ({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
],
partials: [
Partials.Channel
],
})
apparently not the error comes out before the client successfully logs in i'm kinda nodejs newbie so apologies if i'm making nodejs mistakes instead of discordjs mistakes, if i do, please refer me to a documentation that i can read ...it worked. can you tell me how before i mark the post as solved? both seemed the same for me. i see. thank you for helping me.
Want results from more Discord servers?
Add your server