trying to create a voice channel in a parent category

I'm trying to make a slash command that when used will create a voice chat and then delete it when everyone leaves. this works fine when creating a channel with no parent category
// Check if this Channel where the command was used is stray
if (!interaction.channel.parent) {
await interaction.guild.channels.create({
name: chosenVoiceChannelName,
type: ChannelType.GuildVoice,
});
await interaction.editReply({
content: "Your voice channel was successfully created!",
});
return;
}
// Check if this Channel where the command was used is stray
if (!interaction.channel.parent) {
await interaction.guild.channels.create({
name: chosenVoiceChannelName,
type: ChannelType.GuildVoice,
});
await interaction.editReply({
content: "Your voice channel was successfully created!",
});
return;
}
but when I check if there is a parent it creates the channel on the "root" level..
// Check if this Channel where the command was used belongs to a Category
if (interaction.channel.parent) {
// If the Channel where the command was used belongs to a Category,
// create another Channel in the same Category.
await interaction.channel.parent.guild.channels.create
name: chosenVoiceChannelName, // The name given to the Channel by the user
type: ChannelType.GuildVoice, // The type of the Channel created.
});

// If we managed to create the Channel, edit the initial response with
// a success message
await interaction.editReply({
content:
"Your voice channel was successfully created in the same category!",
});
return;
}
// Check if this Channel where the command was used belongs to a Category
if (interaction.channel.parent) {
// If the Channel where the command was used belongs to a Category,
// create another Channel in the same Category.
await interaction.channel.parent.guild.channels.create
name: chosenVoiceChannelName, // The name given to the Channel by the user
type: ChannelType.GuildVoice, // The type of the Channel created.
});

// If we managed to create the Channel, edit the initial response with
// a success message
await interaction.editReply({
content:
"Your voice channel was successfully created in the same category!",
});
return;
}
what am I missing Ideally I would like to use the command in a thread such as this and have it create a voice channel at the top of the category. my test env is not setup for threads but I want it to be in the category of the threads, not in the thread. for instance this category is called DISCORD.JS SUPPORT create a voice channel in the category "node": "20.16.0" "discord.js": "^14.15.3",
5 Replies
d.js toolkit
d.js toolkit3w 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! - Marked as resolved by OP
treble/luna
treble/luna3w ago
1) thats not valid js syntax, looks like your code got cut off 2) you are getting the parent but still calling <Guild>.channels.create so it indeed will create it at the root level either pass in the id or call create on the children
CKY
CKYOP3w ago
thank you
await interaction.channel.parent.children.create({
await interaction.channel.parent.children.create({
returns
Property 'children' does not exist on type 'CategoryChannel | NewsChannel | TextChannel | ForumChannel | MediaChannel'.
Property 'children' does not exist on type 'NewsChannel'.ts(2339)
Property 'children' does not exist on type 'CategoryChannel | NewsChannel | TextChannel | ForumChannel | MediaChannel'.
Property 'children' does not exist on type 'NewsChannel'.ts(2339)
in the ide and wont compile out. channel.parent is returning type 'CategoryChannel | NewsChannel | TextChannel | ForumChannel | MediaChannel' and not ChannelType.GuildCategory is there a typings that im missing?
treble/luna
treble/luna3w ago
you need to compare it
CKY
CKYOP3w ago
thank you both thats what i was missing parent: category as CategoryChannel

Did you find this page helpful?