1
votes

I made a discord bot, if an user enters in a specific voice channel, an another voice channel is temporary created and the user is moved in. But the channel which the bot created goes to the top of the discord server and it goes into "Temporary Channels". So you can see my problem on the screen, the temporary channel moves all the existing channel and if there are lots of users on the server ... It creates a problem.

https://gyazo.com/05853a3ba35d2850d60207459b0075ea

I tried with createChannel() or clone(), it works but with the same problem.

client.on('voiceStateUpdate', (oldMember, newMember) => {
    const defaultCategory = '542554305194885120';
    const defaultCreate = '541105891248701450';
    if(newMember.voiceChannelID === defaultCreate){
    newMember.guild.createChannel(`Salon de ${newMember.user.username}`, 'voice')
        .then(tempChannel => {
            tempChannel.setParent(defaultCategory);
            newMember.setVoiceChannel(tempChannel.id);
        })
        .catch(console.error);
    }
});

I want to create a channel in "temporary channels" category, not by creating first on the top, on discord server then moving into the category

Thank you for your help.

2

2 Answers

0
votes

I don't think it's possible to create a channel directly as a child of a category channel. client.guild.createChannel() does not have any option related to position.

0
votes

UPDATE: 2020/12/22: You can use this package: https://www.npmjs.com/package/discord.js-temporary-channel This for Discord.js

client.on('voiceStateUpdate', (oldMember, newMember) => {
    // todo create channel
    if (newMember.voiceChannel != null && newMember.voiceChannel.name.startsWith('+ ')) {
        newMember.guild.createChannel(`- ${newMember.displayName}`, {
            type: 'voice',
            parent: newMember.voiceChannel.parent
       }).then(cloneChannel => newMember.setVoiceChannel(cloneChannel))
    }
    // ! leave
    if (oldMember.voiceChannel != undefined) {
        if (oldMember.voiceChannel.name.startsWith('- ')) {
            if (oldMember.voiceChannel.members.size == 0) {
                oldMember.voiceChannel.delete()
            }
            else { // change name
                let matchMember = oldMember.voiceChannel.members.find(x => `- ${x.displayName}` == oldMember.voiceChannel.name);
                if (matchMember == null) {
                    oldMember.voiceChannel.setName(`- ${oldMember.voiceChannel.members.random().displayName}`)
                }
            }
        }
    }
});

Thanks to Pie from reddit vn

You need a create channel like this https://imgur.com/a/vQ8xwTY and https://discord.js.org/#/docs/main/stable/class/VoiceChannel?scrollTo=clone