The code created category and channel and gave me this error: TypeError: Cannot read property 'hasOwnProperty' of undefined
without moving the channel in the category
This is the code to the error:
const guild = message.guild;
const channel = await guild.channels.create(`ticket: ${message.author.tag}`);
let category = guild.channels.cache.find(c => c.name == "Tickets" && c.type == "category")
if (!category) {
type: 'category',
})
.catch(console.error);
}
channel.setParent(category);
Advertisement
Answer
The channel.setParent
call fails on this line since category
is undefined
. Looks like the guild does not have a category channel named 'Tickets'
.
Since you’re creating the channel if it doesn’t exist, you should await
it and reassign category
to the newly created channel to use in the channel.setParent
call.
if (!category) {
category = await server.channels.create('Tickets', {
type: 'category',
// ...
})
}
channel.setParent(category)
Btw, it looks like updateOverwrite
is not a valid option in the server.channels.create
call. I think it should be permissionOverwrites
. Check the docs.
This is unrelated to the question but I would recommend renaming category
to categoryChannel
for clarity.