Please don't comment if think that what I'm asking is stupid.
I am completely new to this. I tried searching up solutions but couldn't find helpful ones or ones that a noob in discord.js would understand. Thank you for your help in advance!
const express = require ("express")
var app = require('express')();
app.get("/", (req, res) => {
res.send("hello hell!")
})
app.listen(3000, () => {
console.log("Project is ready")
})
let Discord = require("discord.js")
let client = new Discord.Client()
client.on('voiceStateUpdate', (oldVoiceState, newVoiceState) => {
let newUserChannel = newVoiceState.voiceChannel
let oldUserChannel = oldVoiceState.voiceChannel
if(oldUserChannel === undefined && newUserChannel !== undefined) {
// User Joins a voice channel
console.log(client.voiceConnections.size)
} else if(newUserChannel === undefined){
// User leaves a voice channel
console.log(client.voiceConnections.size)
}
})
client.login("token")
repl.it
outcome when someone joins
Project is ready
console.log(client.voiceConnections.size)
^
TypeError: Cannot read property 'size' of undefined
at Client.<anonymous> (/home/runner/VCC-Bot/index.js:30:37)
at Client.emit (events.js:315:20)
at Client.EventEmitter.emit (domain.js:483:12)
at VoiceStateUpdate.handle (/home/runner/VCC-Bot/node_modules/discord.js/src/client/actions/VoiceStateUpdate.js:40:14)
at Object.module.exports [as VOICE_STATE_UPDATE] (/home/runner/VCC-Bot/node_modules/discord.js/src/client/websocket/handlers/VOICE_STATE_UPDATE.js:4:35)
at WebSocketManager.handlePacket (/home/runner/VCC-Bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/home/runner/VCC-Bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/home/runner/VCC-Bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/home/runner/VCC-Bot/node_modules/ws/lib/event-target.js:132:16)
at WebSocket.emit (events.js:315:20)
question from:
https://stackoverflow.com/questions/65893829/trying-to-make-a-bot-that-counts-members-in-a-voice-channel 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…