#well you dont assign dynamicChannel to

1 messages · Page 1 of 1 (latest)

ember wigeon
#

What do you mean?

deft wedge
#

you want to send messages to the new channel right

ember wigeon
#
 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

deft wedge
#

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

ember wigeon
#
 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?

deft wedge
#

sure

ember wigeon
#

hmm but im getting error after trying to send that message

deft wedge
#

that error is most likely coming from a different place

ember wigeon
#

just debugged and ye it breaks on
.then(channel => channel.send(message))

ember wigeon
deft wedge
#

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?

ember wigeon
#

i was

deft wedge
#

yeah so the channel variable is only available inside the .then, because that is where it is defined

ember wigeon
#

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

deft wedge
#

because you are looking for the channel before creating it

ember wigeon
#

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

deft wedge
#

okay, does it not find it even when you look for a channel name that exists?

ember wigeon
#

yep

deft wedge
#

do you have the Guilds intent?

ember wigeon
#

yes i do wait

#

i must have channel name in lowercase right?

deft wedge
#

same case that it's named

#

but i think text channels can only be lowercase anyway

ember wigeon
#

yeeee

#

Channel is created with .toLowerCase()

#

and my parameter for channel name isnt

#

so thats why it didnt find anything

deft wedge
#

if you have a channel #test and you look for "Test" it wont find anything

ember wigeon
#

yep that was the problem

deft wedge
ember wigeon
#

ye literally :D

#

Big thanks hope you have a great evening/morning/day ❤️