Trying to create a channel under a category

code:
client.on('guildMemberAdd', async member => {
const guild = member.guild;

// Find the verification category by name (case-insensitive)
const verificationCategory = guild.channels.cache.find(channel => channel.type === 'GUILD_CATEGORY' && channel.name.toLowerCase() === 'verification');

if (!verificationCategory) {
console.error('Verification category not found.');
return;
}

const everyoneRole = guild.roles.everyone;

try {
// Create a private channel for the user under the verification category
const channel = await guild.channels.create({
name: `verification-${member.user.username}`,
type: 'text', // Text channel
parent: verificationCategory, // Set the verification category as the parent

//More code after this but I've tested it and it works. The error only happens when trying to set the parent:
client.on('guildMemberAdd', async member => {
const guild = member.guild;

// Find the verification category by name (case-insensitive)
const verificationCategory = guild.channels.cache.find(channel => channel.type === 'GUILD_CATEGORY' && channel.name.toLowerCase() === 'verification');

if (!verificationCategory) {
console.error('Verification category not found.');
return;
}

const everyoneRole = guild.roles.everyone;

try {
// Create a private channel for the user under the verification category
const channel = await guild.channels.create({
name: `verification-${member.user.username}`,
type: 'text', // Text channel
parent: verificationCategory, // Set the verification category as the parent

//More code after this but I've tested it and it works. The error only happens when trying to set the parent:
Error message -> Verification category not found. It's saying the category doesn't exist but it very much does. I've also tried using the exact ID for it and it still doesn't work. What am i doing wrong? I also cut the code snippet to make it fit in here
4 Replies
d.js toolkit
d.js toolkit•6mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Unknown User
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs•6mo ago
:property: BaseChannel#type @14.15.2 The type of the channel
Vikram
VikramOP•6mo ago
Thank you! gonna try that out when I'm back home and post results 🙂
Want results from more Discord servers?
Add your server