Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

295
Views
Can you stream Audio from a URL in a discord.js resource

How do I play audio from a url with discord.js v13.

I used this code and it didn't work.

    const connection = joinVoiceChannel({
        channelId: channel_id.id,
        guildId: guild_id,
        adapterCreator: message.guild.voiceAdapterCreator,
    });

    const player = createAudioPlayer();
    const resource = createAudioResource('http://radioplayer.kissfmuk.com/live/')
    player.play(resource)

    connection.subscribe(player)

I have activated all Intents, the bot shows a green circle but no audio is playing. Do you have an Idea how it works?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

A link of which you are trying to make a resource of, has to return an audio file. Live audio broadcasts will not work with your current code. If the url gives you E.g. an .mp3 file, the code should work.

Example Function:

const Discord = require('discord.js');
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES] });

const config =  require('./config/config.json');

const { joinVoiceChannel, createAudioPlayer, NoSubscriberBehavior, createAudioResource, AudioPlayerStatus, VoiceConnectionStatus, entersState } = require('@discordjs/voice');
const { join } = require('path');

client.once('ready', () => {
    console.log(config.onlineMessage);
    const channels = client.guilds.cache.find(f => f.name==="<Server Name>").channels;
    JoinChannel(channels.cache.find(r => r.name === "<Channel Name>"), './background.mp3', 0.025);  
});

client.login(config.token);

function JoinChannel(channel, track, volume) {
    const connection = joinVoiceChannel({
        channelId: channel.id,
        guildId: channel.guildId,
        adapterCreator: channel.guild.voiceAdapterCreator,
    });
    const player = createAudioPlayer();
    resource = createAudioResource(join(__dirname, track), { inlineVolume: true });
resource.volume.setVolume(volume);
    connection.subscribe(player); 
    connection.on(VoiceConnectionStatus.Ready, () => {console.log("ready"); player.play(resource);})
    connection.on(VoiceConnectionStatus.Disconnected, async (oldState, newState) => {
        try {
            console.log("Disconnected.")
            await Promise.race([
                entersState(connection, VoiceConnectionStatus.Signalling, 5_000),
                entersState(connection, VoiceConnectionStatus.Connecting, 5_000),
            ]);
        } catch (error) {
            connection.destroy();
        }
    });
    player.on('error', error => {
        console.error(`Error: ${error.message} with resource ${error.resource.metadata.title}`);
        player.play(getNextResource());
    });
    player.on(AudioPlayerStatus.Playing, () => {
        console.log('The audio player has started playing!');
    }); 
    player.on('idle', () => {
        connection.destroy();
    })
}
about 4 years ago · Juan Pablo Isaza Report

0

The answer was pretty simple, I just need to subscribe to the connection before I play the resource!

    const connection = joinVoiceChannel({
        channelId: channel_id.id,
        guildId: guild_id,
        adapterCreator: message.guild.voiceAdapterCreator,
    });


    const resource = 
    createAudioResource('https://streams.ilovemusic.de/iloveradio8.mp3', {
        inlineVolume: true
    })

    const player = createAudioPlayer();
    connection.subscribe(player)
    player.play(resource)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!