I have connected two discord bot accounts to one script and i want to kick a user when they leave a voice channel but it doesn't work. code:
const { Client, Intents, ClientUser } = require('discord.js');
const cli = require('nodemon/lib/cli');
const clients = [ new Client({ intents: [Intents.FLAGS.GUILDS] }), new Client({ intents: [Intents.FLAGS.GUILDS] }) ];
const Tokens = ["token1", "token2"]
clients.forEach(function(client, index) {
client.login(Tokens[index])
let clientcount = index + 1
client.on("ready", () => {
client.user.setUsername("PartyChat Bot")
client.user.setActivity(`PartyChat Bot #${clientcount}`)
console.log(`PartyBot #${clientcount} is online`)
})
});
clients.forEach(function(client, index) {
client.on('voiceStateUpdate', (oldState, newState) => {
let newUserChannel = newState.voiceChannel
let oldUserChannel = oldState.voiceChannel
if(oldUserChannel === undefined && newUserChannel !== undefined) {
// User Joins a voice channel
} else if(newUserChannel === null){
console.log("user left")
newState.member.kick()
}
})
});
if(oldState.channel && !newState.channel){
// code block
}
this detects if user was in channel and left without joining new channel.