Updates to join (server/client)

- Check if the available nodes are connected to a vc in the given guild
This commit is contained in:
Logan Cusano
2024-02-11 04:32:58 -05:00
parent b78fa8307d
commit ed33654b8c
4 changed files with 103 additions and 23 deletions

View File

@@ -7,6 +7,7 @@ import {
AudioPlayerStatus,
VoiceConnectionStatus,
joinVoiceChannel,
getVoiceConnection,
} from '@discordjs/voice';
import { GatewayIntentBits } from 'discord-api-types/v10';
@@ -90,6 +91,12 @@ export async function getVoiceChannelFromID(client, channelID) {
return client.channels.cache.get(channelID)
}
export async function checkIfConnectedToVC(guildId) {
const connection = getVoiceConnection(guildId)
console.log("Connection!", connection);
return connection
}
export async function initDiscordBotClient(token, readyCallback){
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.MessageContent],

View File

@@ -1,5 +1,5 @@
import { io } from "socket.io-client";
import { connectToChannel, initDiscordBotClient, getVoiceChannelFromID } from '../discordAudioBot/dab.mjs';
import { connectToChannel, initDiscordBotClient, getVoiceChannelFromID, checkIfConnectedToVC } from '../discordAudioBot/dab.mjs';
import { logIntoServerWrapper, sendNodeUpdateWrapper } from "./socketClientWrappers.mjs";
export const initSocketConnection = async (localNodeConfig) => {
@@ -25,8 +25,23 @@ export const initSocketConnection = async (localNodeConfig) => {
});
});
socket.on('node-leave', () => {
socket.on('node-leave', async () => {
console.log("Leave requested");
const connection = await getVoiceConnection(myVoiceChannel.guild.id);
if (connection) {
console.log("There is an open VC connection, closing it now");
connection.destroy();
}
});
socket.on('node-check-connected-status', async (guildId, socketCallback) => {
console.log("Requested status check");
if (await checkIfConnectedToVC(guildId)) {
console.log("There is an open VC connection");
socketCallback(true);
} else {
socketCallback(false);
}
});
socket.on('disconnect', () => {