Search code examples
javascriptnode.jsbotsdiscorddiscord.js

Discord.js How access to voice channel in voice channels in category?


const guild_id, channel_id;

const category = client.guilds.get(guild_id).channels.get(channel_id);
const voice_channels = category.children.find(c => c.type == 'voice');

I'm set up this. I'm getting voice channels but i can't delete someone of voice channels in this category.


Solution

  • Do you want to delete a channel you get? - Does the bot have permissions?

    var voice_channels = category.children.find(c => c.type == 'voice');
    

    - returns first voice channel

    If you want to get every channel, use:

    var voice_channels = category.children.filter(c => c.type == 'voice');
    

    Deleting a channel: https://discord.js.org/#/docs/main/stable/class/Channel?scrollTo=delete

    var voice_channels = category.children.filter(c => c.type == 'voice');
    //Discord.js version 12 (I believe)
    var channels = voice_channels.map(e => client.channels.resolve(e))
    channels[1].delete()
    //use client.channels.get(e) in older versions