How can I send a message to this channel?

Hey, how can I send a message to this channel?
const { Events, EmbedBuilder } = require("discord.js");
const { db } = require("../database.js");

module.exports = {
name: Events.GuildCreate,
once: false,
async execute(guild) {
const channelId = 1224860828784918528
const guildOwner = await guild.fetchOwner()
const dmEmbed = new EmbedBuilder()
.setColor('Blurple')
.setTitle('Getting Started')
.setDescription(`Thank you for choosing Bridgify! Run the **/help** command to see my available commands!`)
.setThumbnail(process.env.ICON_URL)
.setTimestamp();

await guildOwner.send({ embeds: [dmEmbed] }).catch(() => null);

db.collection("guild-data").insertOne({guildId: guild.id})
console.log(`[INFO] >>> I was just added to a new guild: ${guild.name} | ${guild.id} | Owner ID: ${guild.ownerId} | Size: ${guild.memberCount}`);

const channel = guild.channels.cache.get(channelId)

await channel.send("test worked")
}
}
const { Events, EmbedBuilder } = require("discord.js");
const { db } = require("../database.js");

module.exports = {
name: Events.GuildCreate,
once: false,
async execute(guild) {
const channelId = 1224860828784918528
const guildOwner = await guild.fetchOwner()
const dmEmbed = new EmbedBuilder()
.setColor('Blurple')
.setTitle('Getting Started')
.setDescription(`Thank you for choosing Bridgify! Run the **/help** command to see my available commands!`)
.setThumbnail(process.env.ICON_URL)
.setTimestamp();

await guildOwner.send({ embeds: [dmEmbed] }).catch(() => null);

db.collection("guild-data").insertOne({guildId: guild.id})
console.log(`[INFO] >>> I was just added to a new guild: ${guild.name} | ${guild.id} | Owner ID: ${guild.ownerId} | Size: ${guild.memberCount}`);

const channel = guild.channels.cache.get(channelId)

await channel.send("test worked")
}
}
node:events:495
throw er; // Unhandled 'error' event
^
TypeError: channel.send is not a function
at Object.execute (/home/container/src/events/guildCreate.js:30:23)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:398:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)
Node.js v18.20.0
node:events:495
throw er; // Unhandled 'error' event
^
TypeError: channel.send is not a function
at Object.execute (/home/container/src/events/guildCreate.js:30:23)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:398:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)
Node.js v18.20.0
2 Replies
d.js toolkit
d.js toolkit9mo 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!
NyR
NyR9mo ago
Because channel is undefined, i see you have defined channelId as a number, make it a string Discordjs uses string for snowflakes Also, you are getting the channel from the newly joined guild, but you are passing a pre defined id, that doesn't make sense, since how do you know the id of a channel in a guild your bot has not yet joined (unless this is for testing purposes), but still you should get it from the <Client>.channels.cache
Want results from more Discord servers?
Add your server