1
votes
async function CreateChannel(msg,channelName){
      return await Promise.resolve(msg.guild.channels.create(channelName,{parent: 'PARENT_ID'})
      .then((msg.channel.send(`${channelName} named channel created !!`)))
      .catch(console.error));
}

function SendMessageToChannel(msg,message,channelName){

      const channel = msg.guild.channels.cache.find(ch => ch.name === channelName);
      if(!channel) return;
      channel.send(message);
}

I used the above two functions for a specific command to create a channel

eg: !channel surf creates a new channel name with surf.

What I want is when channel is created I want to automatically create a greeting message like

Welcome to Channel!

But What I'm facing not sending through code in SendMessageToChannel because the cache of the message guild is not updating.

Help me with this!!

Thank You in advance

1

1 Answers

0
votes

Solution for my problem

async function CreateChannel(msg,channelName){
const channelCheck = msg.guild.channels.cache.find(ch => ch.name == channelName);
if(!channelCheck){
    return await Promise.resolve(msg.guild.channels.create(channelName,{parent: '706748967790182401'})
    .then(() => {
        msg.channel.send(`${channelName} named channel created !!`);
        SendMessageToChannel(msg,`Welcome to the ${channelName}!`,channelName);
    })
    .catch(console.error));
}
else{
    msg.reply(`${channelName} already exists!`);
}
}

Instead of calling SendMessageToChannel after CreateChannel I called when Channel Creation promise is resolved so after the creation of channel immediate greeting/message can be send.