Vikram
Vikram
DIAdiscord.js - Imagine an app
Created by Vikram on 6/8/2024 in #djs-questions
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
6 replies