Reputation: 1
I am trying this JavaScript ticket code in my discord bot, but the error TypeError: Cannot read property 'guild' of undefined
keeps showing up. I don't understand why. Could someone guide me in the correct direction?
module.exports = {
name: "ticket",
aliases: [],
permissions: [],
description: "Open a ticket!",
async execute(message, args, cmd, client, discord) {
const channel = await message.guild.channels.create(`ticket: ${message.author.tag}`);
channel.setParent("820276801652916270");
channel.updateOverwrite(message.guild.id, {
SEND_MESSAGE: false,
VIEW_CHANNEL: false,
});
channel.updateOverwrite(message.author, {
SEND_MESSAGE: true,
VIEW_CHANNEL: true,
});
const reactionMessage = await channel.send("Thank you for contacting support!");
try {
await reactionMessage.react("🔒");
await reactionMessage.react("â›”");
} catch (err) {
channel.send("Error sending emojis!");
throw err;
}
const collector = reactionMessage.createReactionCollector(
(reaction, user) => message.guild.members.cache.find((member) => member.id === user.id).hasPermission("ADMINISTRATOR"),
{ dispose: true }
);
collector.on("collect", (reaction, user) => {
switch (reaction.emoji.name) {
case "🔒":
channel.updateOverwrite(message.author, { SEND_MESSAGES: false });
break;
case "â›”":
channel.send("Deleting this channel in 5 seconds!");
setTimeout(() => channel.delete(), 5000);
break;
}
});
message.channel
.send(`We will be right with you! ${channel}`)
.then((msg) => {
setTimeout(() => msg.delete(), 7000);
setTimeout(() => message.delete(), 3000);
})
.catch((err) => {
throw err;
});
},
}
Upvotes: 0
Views: 155
Reputation: 448
Using the info in your comment, your command handler was set up incorrectly. When you put execute(message.args)
, the code tried to pass the args
property of your message argument which returns undefined
.
Instead, you should use execute(message, args)
to properly pass in each argument for your command.
Upvotes: 1