javascriptdiscorddiscord.jsvoice

Discord.js code works fine while playing local files, while trying to play urls it doesn't play anything




const Discord = require('discord.js');

const { Client, GatewayIntentBits } = require('discord.js');

const client = new Client({ intents:

  [

      GatewayIntentBits.Guilds,

      GatewayIntentBits.GuildMessages,

      GatewayIntentBits.GuildVoiceStates,

]

});

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

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

const { join } = require('path');

client.once('ready', async() => {

    console.log("connected");

    const channels = client.guilds.cache.find(f => f.name==="<my-guild>").channels;

  let channel= channels.cache.find(r => r.name === "General");

const connection = joinVoiceChannel({

channelId: channel.id,

guildId: channel.guildId,

adapterCreator: channel.guild.voiceAdapterCreator,

});                                                                                                                                         console.log("joined voice channel");

const player = createAudioPlayer();

let resource = createAudioResource("https://streams.ilovemusic.de/iloveradio2.mp3", { inlineVolume: true,

  inputType: StreamType.Arbitrary});

resource.volume.setVolume(1)

connection.subscribe(player);

player.play(resource);

});

client.login(config.token);

It worked fine last month, Trying to run it this month and nothing is heard via stream, but local audio files work fine.

Expectation: Url should play as discord createAudioResource supports urls.

The main problem is local files play, while remote urls don't. There's no error though so I am confused on how to debug it.


Solution

  • It should a problem of ffmpeg installation, tried running the script on a new machine (after installing ffmpeg) and it works fine.