This is pretty easy to solve. The problem is that voiceStateUpdate
does indeed take two variables, however they are not oldMember, newMember
but oldState, newState
.
As usual with functions it doesn’t really matter what you call them but it makes more sense to use oldState, newState
because they are a voiceState
. As such they do not have a voice
property.
So to fix this, all you have to do is use the correct voiceState properties.
const newUserChannel = newState.channelID;
const oldUserChannel = oldState.channelID;
Note: newState.user
is also not a thing, however it does provide you with the member
object so I suggest you use that instead.
EDIT: Your entire code should look a little something like this.
bot.on('voiceStateUpdate', (oldState, newState) => {
const newUserChannel = newState.channelID;
const oldUserChannel = oldState.channelID;
const textChannel = newState.guild.channels.cache.get('766783720312537089');
if (newUserChannel === '764231813248843806') {
textChannel.send(`${newState.member.user.username} (${newState.id}) has joined the channel`)
} else if (oldUserChannel === '764231813248843806' && newUserChannel !== '764231813248843806') {
textChannel.send(`${newState.member.user.username} (${newState.id}) has left the channel`)
}
});
CLICK HERE to find out more related problems solutions.