#No duplicate tickets in discord.js

21 messages · Page 1 of 1 (latest)

shrewd flare
#

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')
    }
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

#

But this is not working*

#

discord.js v13.8.0

#

node.js v16

#

No errors*

jagged mantle
#

oh wait

fringe edgeBOT
#

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

• Equality and sameness in JavaScript: learn more

shrewd flare
#
let existingChannel = interaction.guild.channels.cache.find(c => c.name == `Ticket-${interaction.user.discriminator}`);
dim venture
#

case sensitive

#

channel names are lowercase

fringe edgeBOT
#

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")
jagged mantle
#

Also this ^

#

For ticketCategory declaration

shrewd flare
amber pelican
#

This will fail for two different members having the same discriminator though…

shrewd flare
amber pelican
#

Because usernames can contain characters invalid for channel names (so they‘d get stripped and not be equal anymore), ids are long and might not be valid channelnames by that