#Audio not playing despite properly retrieving URL to audio. No errors.

7 messages · Page 1 of 1 (latest)

reef lanceBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
visual socket
#
// Imports
const {Client,Events,GatewayIntentBits} = require('discord.js');
const {joinVoiceChannel,createAudioPlayer,createAudioResource,AudioResource,StreamType,getVoiceConnections} = require('@discordjs/voice');

// Client
const client = new Client({intents: [GatewayIntentBits.Guilds,GatewayIntentBits.GuildMessages,GatewayIntentBits.MessageContent]});

async function fetchAudioResource(url) {
    const response = await fetch(url);
    if (!response.ok) throw new Error(`Failed to fetch audio: ${response.statusText}`);
    const resource = createAudioResource(response.body, { inlineVolume: true });
    resource.volume.setVolume(1);
    return resource;
}

// Message handler
client.on('messageCreate', async (message) => {
    if (message.author.bot || !message.guild) return;
    if (!message.content.startsWith(system[0].prefix)) return;

    const args = message.content.slice(system[0].prefix.length).trim().split(/ +/);
    const command = args.shift().toLowerCase();

    if (command === "play") {
        const voiceConnection = joinVoiceChannel({
            channelId: "1318656940884234323",
            guildId: message.guild.id,
            adapterCreator: message.guild.voiceAdapterCreator,
        });

        message.reply("I'm in! Hop on with me in #1318656940884234323");
    }
#
    if (command === "queue") {
        try {
            if (args.length < 1) {
                return message.reply("Please provide a valid audio URL!");
            }
            const audioUrl = args[0];
            const audioResource = await fetchAudioResource(audioUrl);
            const voiceConnection = getVoiceConnections().get(message.guild.id);

            if (!voiceConnection) {
                return message.reply("The bot isn't connected to a voice channel!");
            }

            const player = createAudioPlayer();
            player.play(audioResource);
            voiceConnection.subscribe(player);

            player.on('error', (error) => {
                console.error('Player error:', error.message);
                message.reply("An error occurred during playback.");
            });

            player.on('idle', () => {
                console.log('Finished playing!');
                voiceConnection.destroy();
                message.reply("Finished playing the audio!");
            });

            message.reply("Playing your audio!");
        } catch (error) {
            console.error(error);
            message.reply("Failed to play the audio. Please check the URL and try again.");
        }
    }
});
#

(i did remove the unnecessary lines of code for the purpose of this thread)

#

this is the only feedback i get from the bot

keen shadow
#

#998942774994927646 would be better for this

visual socket
#

OH sorry i didn't notice there was a specific one