voice is playing on local but not on server

Hi Ive got a problem with this code:
if(interaction.commandName === 'musicradio') {

const { createAudioPlayer, createAudioResource, joinVoiceChannel } = require('@discordjs/voice');
const { ActionRowBuilder, StringSelectMenuBuilder } = require('discord.js');

// Code für den Slash Command mit dem Namen "musicradio"
const voiceChannel = interaction.member.voice.channel;

if (!voiceChannel) return interaction.reply('Du musst in einem Voice Channel sein, um mit mir Musik zu hören.');

const radioOptions = [
labels
// Weitere Sender können hier hinzugefügt werden
];

const selectMenu = new StringSelectMenuBuilder()
.setCustomId('radioSelect')
.setPlaceholder('Wähle einen Sender aus')
.addOptions(radioOptions);

const row = new ActionRowBuilder().addComponents(selectMenu);

interaction.reply({
content: 'Wähle einen Sender aus:',
components: [row],
ephemeral: 'true',
}).then(() => {
const filter = i => i.user.id === interaction.user.id && i.customId === 'radioSelect';
const collector = interaction.channel.createMessageComponentCollector({ filter, time: 15000 });

collector.on('collect', async i => {
if (!i.deferred) {
// Der Benutzer hat die Interaktion noch nicht abgeschlossen
const selectedRadio = radioOptions.find(option => option.value === i.values[0]);
if (selectedRadio) {
i.deferUpdate(); // Bestätige die Interaktion, um Timeout-Fehler zu vermeiden
const vconnection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator
});
const resource = createAudioResource(selectedRadio.value, { inlineVolume: true });
const player = createAudioPlayer();

player.on('error', error => {
console.error('Fehler beim Abspielen des Audios:', error.message);
});

vconnection.on('error', error => {
console.error('Fehler beim Verbinden zum Voice-Channel:', error.message);
});

vconnection.subscribe(player);
player.play(resource);

// Nachrichten löschen nach 30 Sekunden
setTimeout(() => {
//interaction.channel.messages.fetch({ limit: 1 }).then(messages => {
// interaction.channel.bulkDelete(messages);
//});
}, 30000); // 30000 Millisekunden = 30 Sekunden

} else {
i.deferUpdate(); // Bestätige die Interaktion, um Timeout-Fehler zu vermeiden
interaction.followUp('Ungültige Auswahl.');
}
} else {
// Die Interaktion wurde bereits abgeschlossen
console.log('Die Interaktion wurde bereits abgeschlossen.');
}
});

collector.on('end', collected => {
if (collected.size === 0) {
interaction.followUp({ content: 'Die Auswahl wurde abgebrochen, weil keine Option ausgewählt wurde.', ephemeral: 'true' });
}
});
});

}
if(interaction.commandName === 'musicradio') {

const { createAudioPlayer, createAudioResource, joinVoiceChannel } = require('@discordjs/voice');
const { ActionRowBuilder, StringSelectMenuBuilder } = require('discord.js');

// Code für den Slash Command mit dem Namen "musicradio"
const voiceChannel = interaction.member.voice.channel;

if (!voiceChannel) return interaction.reply('Du musst in einem Voice Channel sein, um mit mir Musik zu hören.');

const radioOptions = [
labels
// Weitere Sender können hier hinzugefügt werden
];

const selectMenu = new StringSelectMenuBuilder()
.setCustomId('radioSelect')
.setPlaceholder('Wähle einen Sender aus')
.addOptions(radioOptions);

const row = new ActionRowBuilder().addComponents(selectMenu);

interaction.reply({
content: 'Wähle einen Sender aus:',
components: [row],
ephemeral: 'true',
}).then(() => {
const filter = i => i.user.id === interaction.user.id && i.customId === 'radioSelect';
const collector = interaction.channel.createMessageComponentCollector({ filter, time: 15000 });

collector.on('collect', async i => {
if (!i.deferred) {
// Der Benutzer hat die Interaktion noch nicht abgeschlossen
const selectedRadio = radioOptions.find(option => option.value === i.values[0]);
if (selectedRadio) {
i.deferUpdate(); // Bestätige die Interaktion, um Timeout-Fehler zu vermeiden
const vconnection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator
});
const resource = createAudioResource(selectedRadio.value, { inlineVolume: true });
const player = createAudioPlayer();

player.on('error', error => {
console.error('Fehler beim Abspielen des Audios:', error.message);
});

vconnection.on('error', error => {
console.error('Fehler beim Verbinden zum Voice-Channel:', error.message);
});

vconnection.subscribe(player);
player.play(resource);

// Nachrichten löschen nach 30 Sekunden
setTimeout(() => {
//interaction.channel.messages.fetch({ limit: 1 }).then(messages => {
// interaction.channel.bulkDelete(messages);
//});
}, 30000); // 30000 Millisekunden = 30 Sekunden

} else {
i.deferUpdate(); // Bestätige die Interaktion, um Timeout-Fehler zu vermeiden
interaction.followUp('Ungültige Auswahl.');
}
} else {
// Die Interaktion wurde bereits abgeschlossen
console.log('Die Interaktion wurde bereits abgeschlossen.');
}
});

collector.on('end', collected => {
if (collected.size === 0) {
interaction.followUp({ content: 'Die Auswahl wurde abgebrochen, weil keine Option ausgewählt wurde.', ephemeral: 'true' });
}
});
});

}
my bot is not playing music when hosted on a Server but plays music when hosted localy, does anyone has / had the same issue and knows what to fix ? Btw Ive got no errors 😦 Thank you
10 Replies
d.js toolkit
d.js toolkit3mo ago
- What are your intents? GuildVoiceStates is required to receive voice data! - Show what dependencies you are using -- generateDependencyReport() is exported from @discordjs/voice. - Try looking at common examples: https://github.com/discordjs/voice-examples. - 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!
M7MD
M7MD2mo ago
Same, if u know the solution tell me
pat
pat2mo ago
read the message above
M7MD
M7MD3w ago
this?
No description
M7MD
M7MD3w ago
@Qjuh could you help? its not network issues or missing/wrong version of ffmpeg I checked them all All of these are the same in my pc idk why its not working i tried to open a port and it didn’t work Sorry
Genesis
Genesis6d ago
your issue likely is because you're using ffmpeg static download the ffmpeg binaries from the website directly into the server instead
M7MD
M7MD6d ago
No i solved it by opening a port
Genesis
Genesis6d ago
👍
M7MD
M7MD6d ago
is the a big difference between ffmpeg static and binaries in audio quality?
Genesis
Genesis6d ago
there could be ive never had an issue with ffmpeg static but a lot of people do
Want results from more Discord servers?
Add your server