Answer the question
In order to leave comments, you need to log in
What is the correct way to check if a channel exists in discord.js?
So, I am writing a support bot with a ticket function. I tried many ways, but did not find the necessary one in order to prohibit the bot from creating a channel if a person has already asked a question.
Source:
client.on('message', async sbs => {
const userMessageDict ={};
let guild = client.guilds.get("703566530201518110");
let role = guild.roles.find(r => r.name === "@everyone")
let channel = guild.channels.find(c => c.type === 'category' && c.name === 'ticket')
if (!sbs.channel.name.startsWith('support')) return;
if (sbs.content.toLowerCase() === `${config.prefix}sob`) {
var userDiscriminator = sbs.author.discriminator; // начинается
let zapret = guild.channels.find(c => c.type === 'text' && c.name === 'ticket-' + userDiscriminator)
if (typeof zapret !== "undefined") {
return sbs.channel.send("<@" + sbs.author.id + ">, Вы уже задавали вопрос, ожидайте ответа.")
} // заканчивается
var userDiscriminator = sbs.author.discriminator;
let newchannel = await guild.createChannel('ticket-' + userDiscriminator, {
type: 'text',
permissionOverwrites: [{
id: sbs.author.id,
deny: ['MANAGE_MESSAGES'],
allow: ['SEND_MESSAGES']
}, {
id: role.id,
deny: ['VIEW_CHANNEL']
}]
});
userMessageDict[sbs.author.id] = null;
newchannel.setParent(channel.id)
sbs.delete({ timeout: 0 })
.then(() => {
return sbs.channel.send("<@" + sbs.author.id + ">, перейдите в текстовый канал <#" + newchannel.id + ">");
});
setTimeout(() => {
newchannel.delete();
console.log('Канал <#' + newchannel.id + '> был удален по истечению срока действия.')
}, 30000);
}
});
if (typeof zapret !== "undefined")
typeof
undefined
defined
=
!=
Answer the question
In order to leave comments, you need to log in
Actually, I did not wait for an answer, having tried several dozen options, I found a solution.
Maybe someone needs:
let channela = guild.channels.find(c => c.name == 'ticket')
if(channela)
sbs.delete({ timeout: 0 })
.then(() => {
return sbs.channel.send("<@" + sbs.author.id + ">, Вы уже задавали вопрос, ожидайте проверки.");
});
console.log("Канал найден.");
if(!channela) {
console.log("Канал не найден.");
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question