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.
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('я не создала');
}
}
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
};