Skip to content

Unable to play audio from local directory in voice channel (fluxerjs/voice) #31

@Roxanne-Wolf

Description

@Roxanne-Wolf

I can't tell if this is a bug or this is not possible with fluxerjs/core yet but I am unable to play any audio files from a local directory into a voice channel despite them being .webm format. The bot can join a voice channel with the !join command but when I try to play anything with the !play command, it fails with "_FluxerError: Failed to parse URL from ./music/.webm". I could not get far enough to see if the stop command works. Here is my bot code.

const { Client, Events, EmbedBuilder, PermissionFlags, VoiceChannel } = require('@fluxerjs/core');
const { getVoiceManager } = require('@fluxerjs/voice');
const fs = require('fs');
const config = JSON.parse(fs.readFileSync('./config.json', 'utf-8'));
const os = require("os");

const prefix = "!"
const client = new Client({ intents: 0 });
const voiceManager = getVoiceManager(client);

client.on(Events.Ready, () => {
	console.log(`ONLINE and READY!);
});
client.on(Events.Error, (err) => {
	console.error('Error:', err);
});

client.on(Events.MessageCreate, async (message) => {
	if (message.author.bot || !message.content) return;
	if (!message.content.startsWith(prefix)) return;
	const args = message.content.slice(prefix.length).trim().split(/\s+/);
	const command = args.shift()?.toLowerCase();

	if (command === 'join') {
		const voiceManager = getVoiceManager(client);
		const voiceChannelId = voiceManager.getVoiceChannelId(message.guild.id, message.author.id);
		if (!voiceChannelId) return message.reply("It seems like you are not connected to a VC. Please connect to a VC and try again");
		const channel = client.channels.get(voiceChannelId);
		if (!(channel instanceof VoiceChannel)) return;
		await voiceManager.join(channel);
	}
	if (command === 'play') {
		const connection = voiceManager.getConnection(message.guild.id);
		if (!connection) return message.reply("I am not inside your VC.");
		const songid = args.join(' ').trim();
		try {
			await connection.play(`./music/${songid}.webm`);
		} catch (err) {
			console.error(err);
			await message.reply(err);
		}
	}
	if (command === 'stop') {
		const connection = voiceManager.getConnection(channelId) ?? voiceManager.getConnection(guild.id);
		connection?.stop();
		if (connection) voiceManager.leaveChannel(connection.channel.id);
		voiceManager.leave(message.guild.id);
	}
});

(async () => {
	try {
		await client.login("YOUR_BOT_TOKEN_HERE");
	} catch (err) {
		console.error("ERROR:", err);
	}
})();

I tooks the voice functions from https://fluxer.js.org/v/latest/guides/voice btw and never mentioned anything about playing audio from a local audio file which is what I want. I was looking forward to using this since the VC capabilities is within an npm package but it is unusable for me so if someone can give me answers, I would appreciate it as I have nowhere else to go.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions