No duplicate tickets in discord.js

I want to make my bot to not create another ticket if there is an open ticket by the user requesting this action.
const ticketCategory = interaction.guild.channels.cache.find((c) => c.id === "1052297483952345159");

let existingChannel = interaction.guild.channels.cache.find(c => c.name = `Ticket-${interaction.user.discriminator}`);
if (existingChannel) {
return interaction.reply({ content: '❌ There is already a Ticket opened by you!', ephemeral: true });
} else {
return interaction.reply('test')
}
const ticketCategory = interaction.guild.channels.cache.find((c) => c.id === "1052297483952345159");

let existingChannel = interaction.guild.channels.cache.find(c => c.name = `Ticket-${interaction.user.discriminator}`);
if (existingChannel) {
return interaction.reply({ content: '❌ There is already a Ticket opened by you!', ephemeral: true });
} else {
return interaction.reply('test')
}
10 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Pooyan
PooyanOP2y ago
But this is not working* discord.js v13.8.0 node.js v16 No errors*
MrMythical
MrMythical2y ago
Elaborate oh wait
d.js docs
d.js docs2y ago
In JavaScript, = is used for assignment, == for loose equality, and === for strict equality checks.
x = 1; // assigning x to a value
'1' == 1 // true
'1' === 1 // false
x = 1; // assigning x to a value
'1' == 1 // true
'1' === 1 // false
• Equality and sameness in JavaScript: learn more
Pooyan
PooyanOP2y ago
It doesn't work again
let existingChannel = interaction.guild.channels.cache.find(c => c.name == `Ticket-${interaction.user.discriminator}`);
let existingChannel = interaction.guild.channels.cache.find(c => c.name == `Ticket-${interaction.user.discriminator}`);
chewie
chewie2y ago
case sensitive channel names are lowercase
d.js docs
d.js docs2y ago
Don't use the find method to query a Collection by key (mostly the associated id)
- someCollection.find(structure => structure.id === "348607796335607817")
+ someCollection.get("348607796335607817")
- someCollection.find(structure => structure.id === "348607796335607817")
+ someCollection.get("348607796335607817")
MrMythical
MrMythical2y ago
Also this ^ For ticketCategory declaration
Pooyan
PooyanOP2y ago
verify1 Thanks this worked
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server