const { Client, MessageEmbed } = require('discord.js');
const Channel = require('../Classes/channel')
const userDB = require('../Database/user');
module.exports = {
/**
*
* @param {Client} client
*/
run: async (client) => {
client.on('voiceStateUpdate', async (oldStatus, newStatus) => {
const guild = newStatus.guild;
const oldChannel = oldStatus?.channel?.id;
let status;
if(oldStatus.channelId == null) status = 'New'
if(newStatus.channelId == null) status = 'Leave'
if(oldStatus.channelId && newStatus.channelId) status = 'Moved'
if(status == 'New' || status == 'Moved') {
const savedGuild = client.servers.get(newStatus.guild.id);
error:
TypeError: Cannot read properties of undefined (reading 'channels')
at Client.<anonymous> (/bot/Events/manageChannel.js:170:82)
at Client.emit (node:events:527:28)
at VoiceStateUpdate.handle (/bot/node_modules/discord.js/src/client/actions/VoiceStateUpdate.js:38:14)
at Object.module.exports [as VOICE_STATE_UPDATE] (/bot/node_modules/discord.js/src/client/websocket/handlers/VOICE_STATE_UPDATE.js:4:35)
at WebSocketManager.handlePacket (/bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:351:31)
at WebSocketShard.onPacket (/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/bot/node_modules/ws/lib/event-target.js:199:18)
at WebSocket.emit (node:events:527:28)
at Receiver.receiverOnMessage (/bot/node_modules/ws/lib/websocket.js:1160:20)
I already tried catching but idk why this happens (since 1-2 days).
Also I tried client.guilds.cache but then I get TypeError: client.guilds.cache is not a function