#voice is playing on local but not on server

1 messages · Page 1 of 1 (latest)

bitter cradle

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' });
            }
        });
    });
    
}```
 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