Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

192
Visualizações
Discord.js Playing Sound file but no sound is coming out
const Discord = require("discord.js");
require('dotenv').config();
const { joinVoiceChannel, createAudioPlayer, createAudioResource, AudioPlayerStatus } = require('@discordjs/voice');

const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"], partials: ["CHANNEL"] });

const player = createAudioPlayer();

var channelsToMonitor = ['902193996355485778'];

function joinChannel(channel) {
    const connection = joinVoiceChannel({
        channelId: channel.id,
        guildId: channel.guild.id,
        adapterCreator: channel.guild.voiceAdapterCreator,
    });
    return connection;
}

function playAudio(connection) {
    // Subscribe the connection to the audio player (will play audio on the voice connection)
    const resource = createAudioResource('./music/', 'alarm.mp3');
    resource.volume = 1;
    player.play(resource);

    connection.subscribe(player);

    player.on(AudioPlayerStatus.Playing, () => {
        console.log('ALRM');
    });
}

client.on('ready', () => {
    console.log('ready');
})

client.on('messageCreate', async msg => {
    try {
        if (channelsToMonitor.indexOf(msg.channel.id) !== -1) {
            if (msg.content == 'GOGOGO') {
                const guild = client.guilds.cache.get("857332849119723520");
                const channel = guild.channels.cache.get("921415774676058152");
                if (!channel) return console.error("The channel does not exist!");
                var connection = joinChannel(channel);
                await playAudio(connection);
            }
        } else {
            if (msg.author.bot) return;
        }
    } catch (err) {
        console.error(err.message);
    }
});


client.login(process.env.DISCORD_TOKEN_2);

I have set this up from the docs

And I cannot find why no audio is coming out! The bot joins the channel and says it's playing when I use console.log(player) but for some reason, it is deafened and doesn't play any sound.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Bots now join with self deaf by default. Provide the selfDeaf field to stop this:

const connection = joinVoiceChannel({
    channelId: channel.id,
    guildId: channel.guild.id,
    adapterCreator: channel.guild.voiceAdapterCreator,
    selfDeaf: false,
    selfMute: false // this may also be needed
})
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda