const channelName = 'zzz'
const getVoiceChannels = (guild) => {
return guild.channels.cache.filter((channel) => {
return channel.type === 'voice' && channel.name === channelName
})
}
bot.on('voiceStateUpdate', async (oldState, newState) => {
const {guild} = oldState
const joined = !!newState.channelID
const channelId = joined ? newState.channelID : oldState.channelID
const channel = guild.channels.cache.get(channelId)
let channelCreate
if (channel.name === channelName) {
if (joined) {
const channels = getVoiceChannels(guild)
let hasEmpty = false
channels.forEach((channel) => {
if (!hasEmpty && channel.members.size === 0) {
hasEmpty = true
}
})
if (!hasEmpty) {
const {
bitrate,
parentID,
permissionOverwrites,
rawPosition
} = channel
async function createChannel() {
const tempo1 = await guild.channels.create("kanal " + newState.member.user.username + "'s", {
type: "voice",
bitrate,
userLimit: 99,
parent: parentID,
permissionOverwrites,
position: rawPosition
})
await newState.member.voice.setChannel(tempo1)
channelCreate = await guild.channels.cache.get(tempo1.id)
return tempo1
}
await createChannel()
}
}
}
if (channelCreate.members.size === 0) {
channelCreate.delete()
}
})
if (!hasEmpty) {
const {
type,
userLimit,
bitrate,
parentID,
permissionOverwrites,
rawPosition
} = channel
const channelCreate = async () => {
return guild.channels.create("kanal " + newState.member.user.username + "'s", {
type,
bitrate,
userLimit,
parent: parentID,
permissionOverwrites,
position: rawPosition
})
}
// await newState.member.voice.setChannel(channel)
let dasda = channelCreate().then(async (channelObject) => console.log(channelObject.id))
}
// channelCreate = await guild.channels.cache.get(channel.id)
console.log(dasda)
const channelCreate = async () => {
return guild.channels.create("kanal " + newState.member.user.username + "'s", {
type,
bitrate,
userLimit,
parent: parentID,
permissionOverwrites,
position: rawPosition
}).then(async channel => {
await newState.member.voice.setChannel(channel)
})
}
channelCreate().then((channelObject) => console.log(channelObject.id))