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

269
Visualizações
discord.js - Audio Bot creation, only plays sound clips that are less than 50KB

Goal

I want to be able to play longer audio files using my discord bot.

Working Code

Using Discord.js and Node.js, I have created a discord bot. So far my code is able to join a voice call and can only play very short audio files <50KB. Which is great, besides the short file part.

Testing Process: to test different audiofiles, I simply replace the path, during the resource creation, to be the desired audio file.

I have tested 5 short files and it works great! But the three long files >~75KB, that I have, do not work. No errors pop up, it just doesn't play.

const { SlashCommandBuilder } = require('@discordjs/builders');
const { joinVoiceChannel } = require('@discordjs/voice');
const { createAudioPlayer , createAudioResource, StreamType} = require('@discordjs/voice');
const { createReadStream } = require('node:fs');
const { join } = require('node:path');

const { VoiceConnectionStatus, AudioPlayerStatus } = require('@discordjs/voice');




module.exports = {
    data: new SlashCommandBuilder()
        .setName('jensenrage')
        .setDescription('Joins channel and plays jensen\'s rage'),

        
        
    async execute(interaction){
        
        const { joinVoiceChannel } = require('@discordjs/voice');
        const channel = interaction.member.voice.channel

        const connection = joinVoiceChannel({
            channelId: channel.id,
            guildId: channel.guild.id,
            adapterCreator: channel.guild.voiceAdapterCreator,
        });
        
        const resource = createAudioResource(createReadStream(join(__dirname, '../AudioFiles/short.mp3')), {
            inlineVolume : true
            
        });

        resource.volume.setVolume(0.2);

        const player = createAudioPlayer();

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

        await interaction.reply( "Enjoy!")
    }
}

I have looked into why this is, but most of the answers do not explain why the short files play but the long ones do not.

I am assuming that this line is the the issue, but unsure why.

        const resource = createAudioResource(createReadStream(join(__dirname, '../AudioFiles/short.mp3')), {
            inlineVolume : true
            
        });

These are my dependencies

--------------------------------------------------
Core Dependencies
- @discordjs/voice: 0.8.0
- prism-media: 1.3.2
- prism-media: 1.3.2

Opus Libraries
- @discordjs/opus: 0.5.3
- opusscript: 0.0.8

Encryption Libraries
- sodium: not found
- libsodium-wrappers: 0.7.10
- tweetnacl: not found

FFmpeg
- version: 4.4.1-essentials_build-www.gyan.dev
- libopus: yes
about 4 years ago · Juan Pablo Isaza
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