Den
Den
DIAdiscord.js - Imagine an app
Created by Den on 8/29/2023 in #djs-questions
CategoryChildManager create method not working
Hey everyone! I am having trouble creating a child channel within a category. Here is the code
const { Events, ChannelType } = require('discord.js');
const Game = require('../games/gameClass');
const GameCategory = require('../schemas/gameCategory');



let currentGame;
module.exports = {
name: Events.VoiceStateUpdate,
async execute(oldState, newState) {


try {
let currentChannel = newState.channel;

if (currentChannel.full) {
const gameCategoryId = await GameCategory.findOne({ guildId: newState.guild.id });
const gameCategory = await newState.guild.channels.fetch(gameCategoryId.channelId);


console.log('queue full');
let players = [];

for (let i = 0; i < newState.channel.members.size; i++) {
players.push(newState.channel.members.at(i).id);
console.log(i);
}



let gameId = Math.ceil(Math.random() * 10000);
console.log(players);


console.log(gameCategory.id);

// This actually returns the ID of the category, so the category channel is being found.
/*

I am using the .create() method of the category channel. I'm pretty sure the syntax is correct because if I do
newState.guild.channels.create()
with the same syntax, it works.

However, when I try to make a child channel inside of the category, it does not work.
Can somebody please help me :)


*/


await gameCategory.create({
name: `Game-${gameId}`,
type: ChannelType.GuildText
});

}

} catch (err) {

}



},
}


const { Events, ChannelType } = require('discord.js');
const Game = require('../games/gameClass');
const GameCategory = require('../schemas/gameCategory');



let currentGame;
module.exports = {
name: Events.VoiceStateUpdate,
async execute(oldState, newState) {


try {
let currentChannel = newState.channel;

if (currentChannel.full) {
const gameCategoryId = await GameCategory.findOne({ guildId: newState.guild.id });
const gameCategory = await newState.guild.channels.fetch(gameCategoryId.channelId);


console.log('queue full');
let players = [];

for (let i = 0; i < newState.channel.members.size; i++) {
players.push(newState.channel.members.at(i).id);
console.log(i);
}



let gameId = Math.ceil(Math.random() * 10000);
console.log(players);


console.log(gameCategory.id);

// This actually returns the ID of the category, so the category channel is being found.
/*

I am using the .create() method of the category channel. I'm pretty sure the syntax is correct because if I do
newState.guild.channels.create()
with the same syntax, it works.

However, when I try to make a child channel inside of the category, it does not work.
Can somebody please help me :)


*/


await gameCategory.create({
name: `Game-${gameId}`,
type: ChannelType.GuildText
});

}

} catch (err) {

}



},
}


I hope that I wrote my problem in detail 🙂
10 replies