Error with ticket commands in my project

I have error if I try !new why?


const Discord = require("discord.js");
 
const client = new Client()
 
const PREFIX = '!'

//ticket system
const embed3 = new Discord.MessageEmbed()
.setTitle("Ticket Menu")
.setColor(`#f50b0b`)
.setDescription(`**אתה לא יכול לפתוח כרטיס תמיכה משום שיש לך כבר אחד⛔**`)
const embed4 = new Discord.MessageEmbed()
.setTitle("Ticket Menu")
.setColor(`#f50b0b`)
.setDescription(`**אין לך את הגישות בכדי לסגור את כרטיס התמיכה⛔**`)
const embed8 = new Discord.MessageEmbed()
.setTitle("Ticket Reason:")
.setColor(`#06ad22`)
client.on('message', message => {
    if  (message.content.toLowerCase().startsWith(PREFIX + "new")) {
      message.delete();
      let args = message.content.substring(PREFIX.length).split(' ')
        if (!message.guild.roles.exists("name", "ticket")) return message.channel.send(embed4);
        if (message.guild.channels.exists("name","ticket-" + message.author.id)) return message.channel.send(embed3);
        if (message.guild.roles.exists("name", "ticket")) {
            message.guild.createChannel(`Ticket-`, "text").then(g => {
                let role1 = message.guild.roles.find("name", "ticket");
                let role2 = message.guild.roles.find("name", "@everyone");
                g.overwritePermissions(message.author, {
                    READ_MESSAGES: true,
                    SEND_MESSAGES: true
                });
                g.overwritePermissions(role2, {
                    READ_MESSAGES: false,
                    SEND_MESSAGES: false
                });
                g.overwritePermissions(role1, {
                    READ_MESSAGES: true,
                    SEND_MESSAGES: true
                });
                let msgArgs = args.slice(1).join(' ');
                embed8.setDescription(msgArgs)
                g.send(embed8)
 g.send(`${message.author}` + role1)
                const sh2 = new Discord.MessageEmbed()
                .setTitle(`Ticket Menu`)
                .setColor(`#06ad22`)
                .setDescription(`**${g.name} נפתח לך כרטיס תמיכה בשם**`)
                message.channel.send(sh2)
            }
            )
        }
    }
});
const embed1 = new Discord.MessageEmbed()
.setTitle("Ticket Menu")
.setDescription("**Error, You cant close a Non Ticket Channel!**")
.setColor(`#f50b0b`)
const embed7 = new Discord.MessageEmbed()
.setTitle("Ticket Menu")
.setDescription(`**אין לך את הגישות בכדי לסגור את כרטיס התמיכה⛔**`)
.setColor(`#f50b0b`)
client.on('message', message => {
    if (message.content.toLowerCase().startsWith(PREFIX + 'close')) {
        if (!message.channel.name.startsWith(`ticket`)) return message.channel.send(embed1);
        if (!message.member.roles.exists("name", "ticket")) return message.channel.send(embed7);
        message.channel.delete();
    }
})
const embed10 = new Discord.MessageEmbed()
.setTitle("Ticket Menu")
.setDescription("**המשתמש ביקש לסגור את כרטיס התמיכה**")
.setColor(`#f50b0b`)
client.on('message', message => {
    if (message.content.toLowerCase().startsWith(PREFIX + "lock")) {
        if (!message.channel.name.startsWith(`ticket`)) return message.channel.send(`**${message.author} אתה לא יכול לבצע את הפקודה בחדר הזה**`);
        message.channel.send('@here')
        message.channel.send(embed10)
    }
})
client.on('message', message => {
    const embed9 = new Discord.MessageEmbed()
    .setTitle("Ticket Menu")
    .addField("`!new[reason]`", "**פותח לכם כרטיס תמיכה עם הצוות**")
    .addField("`!helpt`", "**שולח לכם את התפריט של פקודות הבוט**")
    .addField("`!lock`", "**פקודה זאת אומרת לאדמינים שעזרו לכם ואין צורך בכרטיס התמיכה**")
    .addField("`!close(לצוות)`", "**סוגר את כרטיס התמיכה**")
    .setThumbnail('https://cdn.discordapp.com/attachments/698679231751913553/706961587230998528/15264.png')
    if (message.content.toLowerCase().startsWith(PREFIX + 'helpt')) {
        message.channel.send(embed9)
    }

})
client.on("message", message => {
  let args = message.content.substring(PREFIX.length).split(" ");
  let msgArgs = args.slice(1).join(" ");

  switch (args[0]) {
    case "say":
      message.delete();
      message.channel.send(msgArgs);
      break;
  }
});

client.on("message", message => {
  let args = message.content.substring(PREFIX.length).split(" ");
  switch (args[0]) {
    case "new":
      const embed = new Discord.MessageEmbed()
        .setTitle("GovRP Ticket BOT - פתיחת טיקט")
        .setColor(0xff0000)
        .setDescription("לרשום לפי הפורמט");

      message.author.send(embed);
      message.delete();
      break;
  }
}); ```

Moving to #discord-help.

Can you state what the error is so I can have a better look at it?

1 Like

I have error here
let args = message.content.substring(PREFIX.length).split(’ ')
if (!message.guild.roles.exists(“name”, “ticket”)) return message.channel.send(embed4);
if (message.guild.channels.exists(“name”,“ticket-” + message.author.id)) return message.channel.send(embed3);
if (message.guild.roles.exists(“name”, “ticket”)) {
message.guild.createChannel(Ticket-, “text”).then(g => {
let role1 = message.guild.roles.find(“name”, “ticket”);
let role2 = message.guild.roles.find(“name”, “@everyone”);
g.overwritePermissions(message.author, {
READ_MESSAGES: true,
SEND_MESSAGES: true
});
g.overwritePermissions(role2, {
READ_MESSAGES: false,
SEND_MESSAGES: false
});

Can show show us the error itself?

Hi! You need to use the message.guild.roles.cache.find function instead.


היי! עליכם להשתמש בפונקציה message.guild.roles.cache.find במקום זאת.

I try and now i have

Help please

Hi! What’s on line 25 of the server.js file?

I send all project
And now I have

        if (!message.guild.roles.cache.find("name", "ticket")) return message.channel.send(embed4);
        if (message.guild.channels.exists("name","ticket-" + message.author.id)) return message.channel.send(embed3);
        if (message.guild.roles.exists("name", "ticket")) {
            message.guild.createChannel(`Ticket-`, "text").then(g => {
                let role1 = message.guild.roles.find("name", "ticket");
                let role2 = message.guild.roles.find("name", "@everyone");
                g.overwritePermissions(message.author, {
                    READ_MESSAGES: true,
                    SEND_MESSAGES: true
                });

Help???
Please

Hi, according to this stack overflow question, you’re using guild.roles.cache.find incorrectly. It works like Array.find, so I think that you need to replace message.guild.roles.cache.find("name", "ticket") with message.guild.roles.cache.find(r => r === "ticket") - but I’d take a look at the <a href=https://discord.js.org/#/docs/collection/master/class/Collection?scrollTo=find>discord.js docs to be certain. You’ll need to replace all instances of the cache.find thing with the function version.

V12 Required the cache() function.