No Sound upon connect

Hey Team! Hope you are all well and had a good halloween. I'm trying to create a /play command which will fetch a URL.mp3, but when the bot joins the channel it doesn't actually play or theres no sound
3 Replies
d.js toolkit
d.js toolkitβ€’3w ago
!GradientWizzard
!GradientWizzardOPβ€’3w ago
🎧 Attempting to join channel "s" in guild "Test". πŸ”Œ Creating voice connection... πŸ›°οΈ VoiceConnection: Signalling... πŸ›°οΈ VoiceConnection: Signalling... ⏳ Waiting for VoiceConnection to reach Ready state... πŸ”„ VoiceConnection: Connecting... πŸ”„ VoiceConnection: Connecting... πŸ”„ VoiceConnection: Connecting... βœ… VoiceConnection: Ready. βœ… VoiceConnection: Ready. βœ… VoiceConnection: Ready. βœ… Voice connection established successfully. 🎡 Creating audio player... πŸ”— Subscribing connection to player... βš™οΈ Launching FFmpeg process for stream transcoding... πŸ”Š Creating audio resource... βœ… Audio resource created, starting playback... ⏳ Player Status: Buffering... πŸš€ Playback started successfully. πŸ“¨ Sending embed confirmation... 🎢 Player Status: Playing live audio. @discordjs/voice@0.19.0
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import {
joinVoiceChannel,
createAudioPlayer,
createAudioResource,
AudioPlayerStatus,
NoSubscriberBehavior,
VoiceConnectionStatus,
entersState
} from '@discordjs/voice';
import prism from 'prism-media';
import ffmpeg from 'ffmpeg-static';

export default {
data: new SlashCommandBuilder()
.setName('play')
.setDescription('Join your current voice channel and play No Name Radio live stream'),

async execute(interaction) {
const streamURL = 'https://link-to-file.mp3';
const memberChannel = interaction.member?.voice?.channel;

if (!memberChannel) {
console.warn('⚠️ User not in a voice channel.');
return interaction.reply({
content: '❌ You need to join a voice channel first!',
ephemeral: true
});
}

await interaction.deferReply();
console.log(`🎧 Attempting to join channel "${memberChannel.name}" in guild "${memberChannel.guild.name}".`);

try {
console.log('πŸ”Œ Creating voice connection...');
const connection = joinVoiceChannel({
channelId: memberChannel.id,
guildId: memberChannel.guild.id,
adapterCreator: memberChannel.guild.voiceAdapterCreator,
selfDeaf: true
});
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import {
joinVoiceChannel,
createAudioPlayer,
createAudioResource,
AudioPlayerStatus,
NoSubscriberBehavior,
VoiceConnectionStatus,
entersState
} from '@discordjs/voice';
import prism from 'prism-media';
import ffmpeg from 'ffmpeg-static';

export default {
data: new SlashCommandBuilder()
.setName('play')
.setDescription('Join your current voice channel and play No Name Radio live stream'),

async execute(interaction) {
const streamURL = 'https://link-to-file.mp3';
const memberChannel = interaction.member?.voice?.channel;

if (!memberChannel) {
console.warn('⚠️ User not in a voice channel.');
return interaction.reply({
content: '❌ You need to join a voice channel first!',
ephemeral: true
});
}

await interaction.deferReply();
console.log(`🎧 Attempting to join channel "${memberChannel.name}" in guild "${memberChannel.guild.name}".`);

try {
console.log('πŸ”Œ Creating voice connection...');
const connection = joinVoiceChannel({
channelId: memberChannel.id,
guildId: memberChannel.guild.id,
adapterCreator: memberChannel.guild.voiceAdapterCreator,
selfDeaf: true
});
connection.on(VoiceConnectionStatus.Signalling, () => console.debug('πŸ›°οΈ VoiceConnection: Signalling...'));
connection.on(VoiceConnectionStatus.Connecting, () => console.debug('πŸ”„ VoiceConnection: Connecting...'));
connection.on(VoiceConnectionStatus.Ready, () => console.log('βœ… VoiceConnection: Ready.'));
connection.on(VoiceConnectionStatus.Disconnected, () => console.warn('⚠️ VoiceConnection: Disconnected.'));
connection.on(VoiceConnectionStatus.Destroyed, () => console.warn('πŸ’€ VoiceConnection: Destroyed.'));
connection.on('error', (err) => console.error('πŸ’₯ VoiceConnection Error:', err));

console.debug('⏳ Waiting for VoiceConnection to reach Ready state...');
await entersState(connection, VoiceConnectionStatus.Ready, 30_000);
console.log('βœ… Voice connection established successfully.');

console.log('🎡 Creating audio player...');
const player = createAudioPlayer({
behaviors: { noSubscriber: NoSubscriberBehavior.Pause }
});

player.on(AudioPlayerStatus.Idle, () => console.debug('⏹️ Player Status: Idle.'));
player.on(AudioPlayerStatus.Buffering, () => console.debug('⏳ Player Status: Buffering...'));
player.on(AudioPlayerStatus.Playing, () => console.log('🎢 Player Status: Playing live audio.'));
player.on(AudioPlayerStatus.AutoPaused, () => console.warn('⏸️ Player Status: AutoPaused.'));
player.on(AudioPlayerStatus.Paused, () => console.debug('⏸️ Player Status: Paused.'));
player.on('error', (err) => console.error('🎧 Player Error:', err));

console.log('πŸ”— Subscribing connection to player...');
const subscription = connection.subscribe(player);
if (!subscription) console.warn('⚠️ No player subscription returned!');
connection.on(VoiceConnectionStatus.Signalling, () => console.debug('πŸ›°οΈ VoiceConnection: Signalling...'));
connection.on(VoiceConnectionStatus.Connecting, () => console.debug('πŸ”„ VoiceConnection: Connecting...'));
connection.on(VoiceConnectionStatus.Ready, () => console.log('βœ… VoiceConnection: Ready.'));
connection.on(VoiceConnectionStatus.Disconnected, () => console.warn('⚠️ VoiceConnection: Disconnected.'));
connection.on(VoiceConnectionStatus.Destroyed, () => console.warn('πŸ’€ VoiceConnection: Destroyed.'));
connection.on('error', (err) => console.error('πŸ’₯ VoiceConnection Error:', err));

console.debug('⏳ Waiting for VoiceConnection to reach Ready state...');
await entersState(connection, VoiceConnectionStatus.Ready, 30_000);
console.log('βœ… Voice connection established successfully.');

console.log('🎡 Creating audio player...');
const player = createAudioPlayer({
behaviors: { noSubscriber: NoSubscriberBehavior.Pause }
});

player.on(AudioPlayerStatus.Idle, () => console.debug('⏹️ Player Status: Idle.'));
player.on(AudioPlayerStatus.Buffering, () => console.debug('⏳ Player Status: Buffering...'));
player.on(AudioPlayerStatus.Playing, () => console.log('🎢 Player Status: Playing live audio.'));
player.on(AudioPlayerStatus.AutoPaused, () => console.warn('⏸️ Player Status: AutoPaused.'));
player.on(AudioPlayerStatus.Paused, () => console.debug('⏸️ Player Status: Paused.'));
player.on('error', (err) => console.error('🎧 Player Error:', err));

console.log('πŸ”— Subscribing connection to player...');
const subscription = connection.subscribe(player);
if (!subscription) console.warn('⚠️ No player subscription returned!');
console.log('βš™οΈ Launching FFmpeg process for stream transcoding...');
const transcoder = new prism.FFmpeg({
args: [
'-reconnect', '1',
'-reconnect_streamed', '1',
'-reconnect_delay_max', '5',
'-i', streamURL,
'-f', 's16le',
'-ar', '48000',
'-ac', '2',
'pipe:1'
],
executable: ffmpeg
});

transcoder.on('spawn', () => console.debug('🧩 FFmpeg process spawned.'));
transcoder.on('error', (err) => console.error('❌ FFmpeg error:', err));
transcoder.on('close', (code, signal) =>
console.log(`🧹 FFmpeg closed (code: ${code}, signal: ${signal}).`)
);

console.debug('πŸ”Š Creating audio resource...');
const resource = createAudioResource(transcoder, { inlineVolume: true });
resource.volume.setVolume(1.0);
console.debug('βœ… Audio resource created, starting playback...');

player.play(resource);
console.log('πŸš€ Playback started successfully.');

const embed = new EmbedBuilder()
.setTitle('πŸ“» Now Streaming Live')
.setDescription(`🎢 Playing in **${memberChannel.name}**`)
.setColor(0x2b2d31)

console.debug('πŸ“¨ Sending embed confirmation...');
await interaction.editReply({ embeds: [embed] });

console.log('βœ… Command execution complete.');
} catch (err) {
console.error('πŸ’₯ Failed to start stream:', err);
await interaction.editReply({
content: '❌ Failed to start the radio stream. Please try again later.'
});
}
}
};
console.log('βš™οΈ Launching FFmpeg process for stream transcoding...');
const transcoder = new prism.FFmpeg({
args: [
'-reconnect', '1',
'-reconnect_streamed', '1',
'-reconnect_delay_max', '5',
'-i', streamURL,
'-f', 's16le',
'-ar', '48000',
'-ac', '2',
'pipe:1'
],
executable: ffmpeg
});

transcoder.on('spawn', () => console.debug('🧩 FFmpeg process spawned.'));
transcoder.on('error', (err) => console.error('❌ FFmpeg error:', err));
transcoder.on('close', (code, signal) =>
console.log(`🧹 FFmpeg closed (code: ${code}, signal: ${signal}).`)
);

console.debug('πŸ”Š Creating audio resource...');
const resource = createAudioResource(transcoder, { inlineVolume: true });
resource.volume.setVolume(1.0);
console.debug('βœ… Audio resource created, starting playback...');

player.play(resource);
console.log('πŸš€ Playback started successfully.');

const embed = new EmbedBuilder()
.setTitle('πŸ“» Now Streaming Live')
.setDescription(`🎢 Playing in **${memberChannel.name}**`)
.setColor(0x2b2d31)

console.debug('πŸ“¨ Sending embed confirmation...');
await interaction.editReply({ embeds: [embed] });

console.log('βœ… Command execution complete.');
} catch (err) {
console.error('πŸ’₯ Failed to start stream:', err);
await interaction.editReply({
content: '❌ Failed to start the radio stream. Please try again later.'
});
}
}
};
Intents:
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates,
],
});
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates,
],
});
-------------------------------------------------- Core Dependencies - @discordjs/voice: 0.19.0 - prism-media: 1.3.5 Opus Libraries - @discordjs/opus: 0.10.0 - opusscript: 0.0.8 Encryption Libraries - native crypto support for aes-256-gcm: yes - sodium-native: not found - sodium: not found - libsodium-wrappers: not found - @stablelib/xchacha20poly1305: not found - @noble/ciphers: not found DAVE Libraries - @snazzah/davey: 0.1.7 FFmpeg - version: 6.0-essentials_build-www.gyan.dev - libopus: yes -------------------------------------------------- β”œβ”€β”€ @discordjs/opus@0.10.0 β”œβ”€β”€ @discordjs/voice@0.19.0 β”œβ”€β”€ @ffmpeg-installer/ffmpeg@1.1.0 β”œβ”€β”€ @snazzah/davey@0.1.7 β”œβ”€β”€ @supabase/supabase-js@2.78.0 β”œβ”€β”€ axios@1.13.1 β”œβ”€β”€ discord.js@14.24.2 β”œβ”€β”€ dotenv@16.6.1 β”œβ”€β”€ ffmpeg-static@5.2.0 β”œβ”€β”€ fluent-ffmpeg@2.1.3 β”œβ”€β”€ luxon@3.7.2 β”œβ”€β”€ opusscript@0.0.8 └── prism-media@1.3.5 I thought opus needed opusscript Well, your such a goat - Managed to fix it πŸ™‚
d.js toolkit
d.js toolkitβ€’3w ago
The thread owner has marked this issue as solved.

Did you find this page helpful?