Update debugging
- Uniform client name
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Debug
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder.js");
|
||||
const log = new DebugBuilder("client-bot", "commandController");
|
||||
const log = new DebugBuilder("client", "commandController");
|
||||
// Modules
|
||||
const { joinVoiceChannel, VoiceConnectionStatus, getVoiceConnection } = require("@discordjs/voice");
|
||||
const { OpusEncoder } = require("@discordjs/opus");
|
||||
@@ -31,7 +31,7 @@ exports.join = async function join({interaction= undefined, guildID= undefined,
|
||||
log.DEBUG("Channel ID: ", channelID)
|
||||
log.DEBUG("Guild ID: ", guildID)
|
||||
|
||||
const voiceConnection = joinVoiceChannel({
|
||||
const voiceConnection = await joinVoiceChannel({
|
||||
channelId: channelID,
|
||||
guildId: guildID,
|
||||
adapterCreator: guildObj.voiceAdapterCreator,
|
||||
@@ -41,21 +41,24 @@ exports.join = async function join({interaction= undefined, guildID= undefined,
|
||||
|
||||
const audioInstance = await createAudioInstance();
|
||||
|
||||
audioInstance.on('audio', (buffer) => {
|
||||
buffer = Buffer.from(buffer);
|
||||
log.DEBUG("Audio buffer: ", buffer);
|
||||
log.VERBOSE("Audio Instance: ", audioInstance);
|
||||
|
||||
audioInstance.on('data', buffer => {
|
||||
//buffer = Buffer.from(buffer);
|
||||
log.VERBOSE("Audio buffer: ", buffer);
|
||||
const encodedBuffer = encoder.encode(buffer);
|
||||
log.DEBUG("Encoded packet: ", encodedBuffer);
|
||||
// TODO Add a function here to check the volume of either buffer and only play audio to discord when there is audio to be played
|
||||
voiceConnection.playOpusPacket(encodedBuffer);
|
||||
})
|
||||
|
||||
// Exit the audio handler when the bot disconnects
|
||||
voiceConnection.on(VoiceConnectionStatus.Destroyed, () => {
|
||||
audioInstance.close();
|
||||
audioInstance.quit();
|
||||
})
|
||||
|
||||
if (guildID && callback) callback();
|
||||
audioInstance.start();
|
||||
|
||||
if (guildID && callback) return callback();
|
||||
else return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user