Script plays local files well but can't play url streams, why?

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==="Riverside").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);
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==="Riverside").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);
5 Replies
d.js toolkit
d.js toolkit15mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - 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!
haiz
haizOP15mo ago
radio@ /home/admin/radio
├── @discordjs/[email protected] -> ./node_modules/.pnpm/@[email protected]/node_modules/@discordjs/opus
├── @discordjs/[email protected] -> ./node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@discordjs/voice
├── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/discord.js
├── [email protected] extraneous -> ./node_modules/.pnpm/[email protected]/node_modules/ffmpeg-static
├── [email protected] extraneous -> ./node_modules/.pnpm/[email protected]/node_modules/ffmpeg
└── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/libsodium-wrappers
radio@ /home/admin/radio
├── @discordjs/[email protected] -> ./node_modules/.pnpm/@[email protected]/node_modules/@discordjs/opus
├── @discordjs/[email protected] -> ./node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@discordjs/voice
├── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/discord.js
├── [email protected] extraneous -> ./node_modules/.pnpm/[email protected]/node_modules/ffmpeg-static
├── [email protected] extraneous -> ./node_modules/.pnpm/[email protected]/node_modules/ffmpeg
└── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/libsodium-wrappers
node -v v18.13.0
Nounejm
Nounejm15mo ago
let player = createAudioPlayer()
connection.subscribe(player)
https.get('url', (res) => {
let resource = createAudioResource(res)
player.play(resource)
})
let player = createAudioPlayer()
connection.subscribe(player)
https.get('url', (res) => {
let resource = createAudioResource(res)
player.play(resource)
})
make sure that the content of the url is an audio or video file
haiz
haizOP15mo ago
It's an audio stream url Nig file *not file
Nounejm
Nounejm15mo ago
it works anyway
Want results from more Discord servers?
Add your server