#well you dont assign dynamicChannel to
1 messages · Page 1 of 1 (latest)
you want to send messages to the new channel right
const dynamicChannel = await guild.channels.cache.find(ch => ch.name == channelName);
if(!dynamicChannel){
await guild.channels.create({
name: channelName,
type: ChannelType.GuildText
})
.then(() => {
console.log(`${channelName} named channel created`);
})
.catch(console.error)
}
else{
console.log(`${channelName} already exists!`);
}
yes
you can do it inside the .then, or assign the .create to a variable
your choice
either way you will get a channel object on which you can use the .send() method
const dynamicChannel = await guild.channels.cache.find(ch => ch.name == channelName);
if(!dynamicChannel){
await guild.channels.create({
name: channelName,
type: ChannelType.GuildText
})
.then(channel => channel.send(message))
.catch(console.error)
}
else{
console.log(`${channelName} already exists!`);
}
like this?
sure
that error is most likely coming from a different place
just debugged and ye it breaks on
.then(channel => channel.send(message))
but weirdly it creates the channel but just doesnt know how to send lol
that's weird, .create should return a promise with a channel object
maybe remove the await, although i dont see how that would cause any problems
and if .create didnt return anything there would be a different error
are you using channel somewhere else?
yeah so the channel variable is only available inside the .then, because that is where it is defined
and another question
const dynamicChannel = guild.channels.cache.find(ch => ch.name == channelName);
if(!dynamicChannel){
await guild.channels.create({
name: channelName,
type: ChannelType.GuildText
})
.then(channel => channel.send(message))
.catch(console.error)
}
else{
console.log(`${channelName} already exists!`);
}
got any ideas maybe why that channel find doesnt find anything
always returns undefined
because you are looking for the channel before creating it
yes i know that is intentional because i want to create a channel if it does not exist and send message there
and if channel exists i just want to send message there
okay, does it not find it even when you look for a channel name that exists?
yep
do you have the Guilds intent?
yeeee
Channel is created with .toLowerCase()
and my parameter for channel name isnt
so thats why it didnt find anything
if you have a channel #test and you look for "Test" it wont find anything

