试图制作一个机器人来计算语音频道中的成员

时间:2021-01-25 23:25:53

标签: discord discord.js

如果认为我问的是愚蠢的,请不要发表评论。 我对此完全陌生。我尝试搜索解决方案,但找不到有用的解决方案或 discord.js 中的菜鸟会理解的解决方案。提前感谢您的帮助!

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 有人加入时的结果 项目准备就绪

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)

0 个答案:

没有答案