Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
Nodejs discord bot

Good afternoon, I have the code, but I can not make checks, let's say if the channel already has a discord channel with this name, the bot displays in a chat error "such a channel already exists," something like this help, please write such a check, if there are other options to address this issue, too, want to hear.

Detailed information

The result variable gets the entire list of channels that are in the discord channel.

Channels.channels[key].Name - this import gets the object from another file where it has only two values, a name and a line of code.

enter image description here

The code is provided below.

function info_channels(robot, mess, args) {
  const result = [];

  robot.channels.cache.forEach(el => {
    let new_key = el.name.replace(re, '');
    result.push(new_key);
    return result;
  });

  for(key in Channels.channels){
    mess.guild.channels.create(`${Channels.channels[key].Name} ${eval(Channels.channels[key].count_users)}`,{
      type: "voice",
      permissionOverwrites: [
        {
          id: mess.guild.roles.everyone,
          allow: [
          'VIEW_CHANNEL',
          'READ_MESSAGE_HISTORY'
          ],
          deny: [
          'CONNECT',
          'MANAGE_CHANNELS',
          'SPEAK'
          ]
        },
        {
          id: mess.guild.roles.cache.get(config.userRole),
          allow: ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY'],
          deny: ['CONNECT','MANAGE_CHANNELS','SPEAK']
        },
        {
          id: mess.guild.roles.cache.get(config.role_Rinka),
          allow: ['VIEW_CHANNEL','MANAGE_CHANNELS','READ_MESSAGE_HISTORY'],
        }
      ],
      parent: '914852886599569458',
    })
    .then(console.log(`Канал${Channels.channels[key].Name.replace(re, '')} создан!`))
    .catch(console.error);
  }

  if (Channels.channels[key].Name === result) {
    mess.channels.send('я создала');    
  } 
  else {
    mess.channel.send('я не создала');
  }

}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could easily check if any channel name starts with any string.

// <Guild> is a placeholder for any Guild object
// <name>  is a placeholder for a channel name you're trying to check
// 
//  Note:  Channels are always cached, no matter what.

const existingChannel = <Guild>.channels.cache.find(chnl => chnl.name.startsWith(<name>);

if (existingChannel) {
    // Channel already exists
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!