Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

348
Views
i'm trying to make my discord bot to record audio using prism-media as said in the example of @discordjs/voice but i'm getting error

I'm making a discord bot that records the voice channel

the libraries discord.js@13.6.0, @discordjs/voice@0.8.0, prism-media@1.3.2

my imports

const { createWriteStream } = require("node:fs")
const { pipeline } = require("node:stream")

const { Client, Intents } = require("discord.js");
const { joinVoiceChannel, getVoiceConnection, EndBehaviorType } = require("@discordjs/voice");
const prism = require('prism-media')

const { token } = require("./secrets.json");

the part of my code that errors

        const oggStream = new prism.opus.OggLogicalBitstream(
            {
                opusHead: new prism.opus.OpusHead({
                    channelCount: 2,
                    sampleRate: 48000,
                }),
                pageSizeControl: {
                    maxPackets: 10,
                },
            }
        );

This is identical to what is shown on the github page of @discordjs/voice https://github.com/discordjs/voice/blob/309ac8596cac422cf22e51331869e011c720124c/examples/recorder/src/createListeningStream.ts#L19

the error

C:\Users\user\OneDrive\Documents\source\discord_bot\index.js:60
                opusHead: new prism.opus.OpusHead({
                          ^

TypeError: prism.opus.OpusHead is not a constructor
    at Client.<anonymous> (C:\Users\user\OneDrive\Documents\source\discord_bot\index.js:60:27)
    at Client.emit (node:events:390:28)
    at VoiceStateUpdate.handle (C:\Users\user\OneDrive\Documents\source\discord_bot\node_modules\discord.js\src\client\actions\VoiceStateUpdate.js:38:14)
    at Object.module.exports [as VOICE_STATE_UPDATE] (C:\Users\user\OneDrive\Documents\source\discord_bot\node_modules\discord.js\src\client\websocket\handlers\VOICE_STATE_UPDATE.js:4:35)
    at WebSocketManager.handlePacket (C:\Users\user\OneDrive\Documents\source\discord_bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:351:31)
    at WebSocketShard.onPacket (C:\Users\user\OneDrive\Documents\source\discord_bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (C:\Users\user\OneDrive\Documents\source\discord_bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
    at WebSocket.onMessage (C:\Users\user\OneDrive\Documents\source\discord_bot\node_modules\ws\lib\event-target.js:199:18)
    at WebSocket.emit (node:events:390:28)
    at Receiver.receiverOnMessage (C:\Users\user\OneDrive\Documents\source\discord_bot\node_modules\ws\lib\websocket.js:1137:20)
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The issue is with your imports:

const { createWriteStream } = require("node:fs") 
const { pipeline } = require("node:stream") 
const { Client, Intents } = require("discord.js"); 
const { joinVoiceChannel, getVoiceConnection, EndBehaviorType } = require("@discordjs/voice"); 
const { opus } = require("prism-media");  // THIS IS THE WRONG BIT
const { token } = require("./secrets.json"); 

You are importing opus from prism-media. You don't have a prism variable. Yet you call it here:

const oggStream = new prism.opus.OggLogicalBitstream( //WRONG
    {
        opusHead: new prism.opus.OpusHead({ //WRONG
            channelCount: 2,
            sampleRate: 48000,
        }),
        pageSizeControl: {
            maxPackets: 10,
        },
        crc: false
    }
);

You didn't import prism though, just prism.opus. Change your code to:

const oggStream = new opus.OggLogicalBitstream(
    {
        opusHead: new opus.OpusHead({
            channelCount: 2,
            sampleRate: 48000,
        }),
        pageSizeControl: {
            maxPackets: 10,
        },
        crc: false
    }
);

Or you can change the import, but that may break other existing code.

const prism = require("prism-media");          // THIS INSTEAD OF
const { opus } = require("prism-media");  // THIS
about 4 years ago · Juan Pablo Isaza Report

0

Use prism-media@2.0.0-alpha.0.

For this:

npm i prism-media@2.0.0-alpha.0
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!