Reputation: 61
So I am working on a Ticketing System for my Discord bot, and my code worked before, but I messed it up, and now it doesn't work.
What I want it to do: When people click the button(discord-buttons) I want it to first check for a category named "Tickets", then make a new channel called "(username)-ticket", and finally, send a embed in the channel that was just made.
What actually happens: The code just says "Cannot read channels of undefined", and does not work.
My Code:
client.on('clickButton', async (button) => {
if (button.id == "ticket") {
let embed = new Discord.MessageEmbed;
embed.setTitle('Created Ticket')
embed.setDescription('Successfully created your ticket.')
await button.reply.send({ embed: embed }, true);
let embed2 = new Discord.MessageEmbed
embed2.setTitle(`Hello, ${button.clicker.user.username}`)
embed2.setDescription('Someone will be with you shortly. To close the ticket, press the ❌ emoji.')
embed2.setFooter('Ticketing System created by FireyJS#6969')
const guild = button.clicker.guild
if (guild.channels.cache.find(c => c.name.toLowerCase() === 'tickets')) {
const category = guild.channels.cache.find(c => c.name.toLowerCase() === 'tickets')
guild.channels.create(`${button.clicker.user.username}-ticket`, { reason : 'Needed to make a ticket lol' }).then(channel => {
channel.setParent(category)
channel.send(embed2)
}).then(message => { message.react('❌') })
} else {
message.channel.send('Make a category named ``Tickets`` to get started with ticketing!')
}
}
});
Upvotes: 0
Views: 1116
Reputation: 448
The button.clicker
object does not have a guild
property, but button
on its own does. Try defining guild
as button.guild
instead of what you currently have!
Upvotes: 1