Where could I be wrong? I have been trying to get it working for several hours, but to no avail, the code does not work. Can anyone help with this?
client.on("voiceStateUpdate",(oldState,newState)=>{
var categoryid = "1081228230321087824";
var channelid = "103284326182943242";
if(newState.channel?.id == channelid){
newState.guild.channels.create(`${newState.member.user.username}'s channel`,{
name: "voice-${user.username}",
type: ChannelType.GuildText,
parent: categoryid,
permissionOverwrites:[{
id: newState.member.id,
allow: ["MANAGE_CHANNELS"]
},{
id: newState.guild.id,
deny:["MANAGE_CHANNELS"]
}]
}).then(channel=>{
newState.setChannel(channel)
channel.createInvite({
maxAge:0,
maxUses:0
})
})
}
if(oldState.channel?.id != channelid && oldState.channel?.parent?.id == categoryid && !oldState.channel?.members.size) oldState.channel.delete();
})
Nothing happens at startup, even errors in the logs do not appear.
Everything was easy and simple, I made a mistake in writing voiceStateUpdate and calling it, I also had a mistake in writing flags.
const newChannel = newState.guild.channels.create({
name: `${newState.member.user.username}'s Channel`,
type: ChannelType.GuildVoice,
parent: newState.channel.parent,
topic: channelid,
permissionOverwrites:[{
id: newState.member.id,
allow: [PermissionsBitField.Flags.ManageChannels]
},{
id: newState.guild.id,
deny:[PermissionsBitField.Flags.ManageChannels]
}]