#Category and Channel fetch issues

1 messages ยท Page 1 of 1 (latest)

sick bison
#

So here's the code when a user selects the option to create a support ticket

The issue: he bot is having trouble findning the right category and channel even if it exists, or having trouble finding a channel it created.

I solved a few steps of it by asking help here and checking docs for 3 days... Anyways here's the code.

case 'newTicket': {
            const reason = int.values[0].split('_')[1];

            const cat = int.guild.channels.cache.find(categ=> categ.name === 'TICKETS' && categ.type === "GUILD_CATEGORY");
            if (!cat) {
        const cat = await int.guild.channels.create("TICKETS", {
                  type: 'GUILD_CATEGORY'
                });
     }
            const ticket = await int.guild.channels.cache.find(x => x.name === `๐Ÿ‚ใƒป${int.member.user.username.toLowerCase()}`);

            if (!ticket) {
                await int.guild.channels.create(`๐Ÿ‚ใƒป${int.member.user.username.toLowerCase()}`, {
                    type: 'GUILD_TEXT',
                    parent: cat.id,
                    topic: `Ticket created by ๐Ÿ‚ใƒป${int.member.user.username}${reason ? ` (${reason})` : ''} ${new Date(Date.now()).toLocaleString()}`,
                    permissionOverwrites: [
                        {
                            id: int.guild.id,
                            deny: ['VIEW_CHANNEL', 'SEND_MESSAGES']
                        },
                        {
                            id: int.member.id,
                            allow: ['VIEW_CHANNEL', 'SEND_MESSAGES']
                        },
                        {
                            id: client.user.id,
                            allow: ['VIEW_CHANNEL', 'SEND_MESSAGES']
                        }
                    ]
                });
#
                const ticketEmbed = new MessageEmbed();

                ticketEmbed.setColor('GREEN');
                ticketEmbed.setAuthor(`Welcome to ${int.guild.name} support! ๐Ÿ‚ใƒป${int.member.user.username}${reason ? ` (${reason})` : ''} โœ…`);
                ticketEmbed.setDescription(`Opened by ๐Ÿ‚ใƒป${int.member.user.username} for ${reason ? ` ${reason}` : ''}. `);

                const closeButton = new MessageButton();

                closeButton.setStyle('DANGER');
                closeButton.setLabel('Close this ticket');
                closeButton.setCustomId(`closeTicket_${int.member.id}`);

                const row = new MessageActionRow().addComponents(closeButton);
const ticket = int.guild.channels.cache.find(x => x.name === `๐Ÿ‚ใƒป${int.member.user.username.toLowerCase()}`);
                await ticket.send({ embeds: [ticketEmbed], components: [row] });

                return int.update({ content: `Your ticket is open <@${int.member.id}> <#${channel.id}> โœ…`, components: [], ephemeral: true });
            } else {
                return int.update({ content: `โŒ Oops, you already have an open ticket: <#${channel.id}> `, components: [], ephemeral: true });
            }
        }
worthy gale
#

is it public or private bot

#

@sick bison

sick bison
worthy gale
#

or is it already on the server

bright vortex
sick bison
#

Here's the error:
Situation: There is no category setup yet and the bot has to create one, and then open the channel in that ticket.

Process: The bot successfully creates the category, but fails to create the ticket under it, resulting in the following error

                    parent: cat.id,
                                ^

TypeError: Cannot read properties of undefined (reading 'id')
bright vortex
sick bison
bright vortex
sick bison
bright vortex
#

const cat is declared inside the if statement

#

Not valid anywhere else

#

So it uses the undefined value from .find

sick bison
bright vortex
worthy gale
bright vortex
# sick bison category

Declare cat like let cat = //find code and in the if statement, just use cat = await ... without const at the start

#

@sick bison did you do it

sick bison
#

can you guys gimme some time till i get back on my pc?

#

im so sorry

#

ill be back in a few hours

bright vortex
sick bison
#

Surew

sick bison
sick bison
sick bison
sick bison
#

@bright vortex @worthy gale sorry this got archived. I just opened it again.

worthy gale
#

log ticket

#

@sick bison

sick bison
worthy gale
#

show were you define it

sick bison
worthy gale
sick bison
worthy gale
#

console.log(ticket)

#

and send screenshot of what you got

#

or

#
if(!ticket) console.log(`no ticket`)```