I'm trying to make an event that when someone added my bot it will send a message embed on a channel that my bot can send the message embed.
discord.js: v13.6.0
Node: v17.7.2
events/guildCreate.js
const client = require("../index");
const discord = require("discord.js")
client.on("guildCreate", async (client, guild) => {
let channel = guild.channels.cache.find(
channel =>
channel.type === "text" &&
channel.permissionsFor(guild.me).has("SEND_MESSAGES")
);
channel.send( new discord.MessageEmbed()
.setDescription("**Thank you for adding me!**")
.setColor("#fcba03"))
})
edit: I kinda of fix my problem with the reading channels:
const client = require("../index");
const { MessageEmbed } = require("discord.js")
client.on("guildCreate", async (guild, message) => {
let channel = guild.channels.cache.find(
channel =>
channel.type === "text" &&
channel.permissionsFor(guild.me).has("SEND_MESSAGES")
);
const embed = new MessageEmbed()
embed.setDescription("Thank you for adding me!")
embed.setColor("#2f3136")
message.guild.channels.cache.get(channel).send(embed)
})
but then again got new error: TypeError: Cannot read properties of undefined (reading 'guild')
I think your “channel” is an array instead of a channel object, because you're filtering all text channels. Make sure to select the first channel of the array/collection.
Try to show what shows up when you log the “channel”