Updates to join (server/client)
- Check if the available nodes are connected to a vc in the given guild
This commit is contained in:
@@ -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],
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user