Recover audio and mute user

Hello I would like to be able to record audio in a voice room (and if possible only record what a user defined by id says) I have not found a clear explanation for version 14 of discord.js, could Can you explain to me how I can achieve my goal?
6 Replies
d.js toolkit
d.js toolkitā€¢14mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - 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! - āœ… Marked as resolved by OP
Kiriox
KirioxOPā€¢14mo ago
Yes I had seen that but I can't get it to work because of a package and it doesn't seem to me that they show how to mute a user
d.js docs
d.js docsā€¢14mo ago
method VoiceState#setMute() Mutes/unmutes the member of this voice state.
Kiriox
KirioxOPā€¢14mo ago
I would like to mute the person but only for the bot so that I only hear that person on the recording I didn't understand your request ok thanks
> @discordjs/[email protected] postinstall
> is-ci || husky install

'is-ci' is not recognized as an internal command
or external, an executable program or batch file.
husky - Git hooks installed

up to date, audited 284 packages in 7s

83 packages are looking for funding
run `npm fund` for details

3 vulnerabilities (2 moderate, 1 high)

To address all issues, run:
npm audit fix

Run `npm audit` for details.
> @discordjs/[email protected] postinstall
> is-ci || husky install

'is-ci' is not recognized as an internal command
or external, an executable program or batch file.
husky - Git hooks installed

up to date, audited 284 packages in 7s

83 packages are looking for funding
run `npm fund` for details

3 vulnerabilities (2 moderate, 1 high)

To address all issues, run:
npm audit fix

Run `npm audit` for details.
Yes but I still wanted to test it so I did npm install as marked in the README and I get this error but I never wanted to import it as a package for my project Finally I just copied the parts of the example that interests me except that I got this error
PS C:\Users\tomto\OneDrive\programation\bot discord\voice_bot> node .\index.js
Ready! Logged in as Roby#2109
C:\Users\tomto\OneDrive\programation\bot discord\voice_bot\index.js:55
opusHead: new prism.opus.OpusHead({
^

TypeError: prism.opus.OpusHead is not a constructor
at createListeningStream (C:\Users\tomto\OneDrive\programation\bot discord\voice_bot\index.js:55:13)
at VoiceConnection.<anonymous> (C:\Users\tomto\OneDrive\programation\bot discord\voice_bot\index.js:37:21)
at VoiceConnection.emit (node:events:513:28)
at set state [as state] (C:\Users\tomto\OneDrive\programation\bot discord\voice_bot\node_modules\@discordjs\voice\dist\index.js:1739:12)
at VoiceConnection.onNetworkingStateChange (C:\Users\tomto\OneDrive\programation\bot discord\voice_bot\node_modules\@discordjs\voice\dist\index.js:1881:18)
at Networking.emit (node:events:513:28)
at set state [as state] (C:\Users\tomto\OneDrive\programation\bot discord\voice_bot\node_modules\@discordjs\voice\dist\index.js:605:10)
at Networking.onWsPacket (C:\Users\tomto\OneDrive\programation\bot discord\voice_bot\node_modules\@discordjs\voice\dist\index.js:739:18)
at VoiceWebSocket.emit (node:events:525:35)
at VoiceWebSocket.onMessage (C:\Users\tomto\OneDrive\programation\bot discord\voice_bot\node_modules\@discordjs\voice\dist\index.js:462:10)

Node.js v18.16.0
PS C:\Users\tomto\OneDrive\programation\bot discord\voice_bot> node .\index.js
Ready! Logged in as Roby#2109
C:\Users\tomto\OneDrive\programation\bot discord\voice_bot\index.js:55
opusHead: new prism.opus.OpusHead({
^

TypeError: prism.opus.OpusHead is not a constructor
at createListeningStream (C:\Users\tomto\OneDrive\programation\bot discord\voice_bot\index.js:55:13)
at VoiceConnection.<anonymous> (C:\Users\tomto\OneDrive\programation\bot discord\voice_bot\index.js:37:21)
at VoiceConnection.emit (node:events:513:28)
at set state [as state] (C:\Users\tomto\OneDrive\programation\bot discord\voice_bot\node_modules\@discordjs\voice\dist\index.js:1739:12)
at VoiceConnection.onNetworkingStateChange (C:\Users\tomto\OneDrive\programation\bot discord\voice_bot\node_modules\@discordjs\voice\dist\index.js:1881:18)
at Networking.emit (node:events:513:28)
at set state [as state] (C:\Users\tomto\OneDrive\programation\bot discord\voice_bot\node_modules\@discordjs\voice\dist\index.js:605:10)
at Networking.onWsPacket (C:\Users\tomto\OneDrive\programation\bot discord\voice_bot\node_modules\@discordjs\voice\dist\index.js:739:18)
at VoiceWebSocket.emit (node:events:525:35)
at VoiceWebSocket.onMessage (C:\Users\tomto\OneDrive\programation\bot discord\voice_bot\node_modules\@discordjs\voice\dist\index.js:462:10)

Node.js v18.16.0
following this piece of code
function createListeningStream(receiver, userId) {
let opusStream = receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 1000,
},
});

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

let filename = `./recordings/${Date.now()}.ogg`;

let out = createWriteStream(filename);

console.log(`šŸ‘‚ Started recording ${filename}`);

pipeline(opusStream, oggStream, out, (err) => {
if (err) {
console.warn(`āŒ Error recording file ${filename} - ${err.message}`);
} else {
console.log(`āœ… Recorded ${filename}`);
}
});
}
function createListeningStream(receiver, userId) {
let opusStream = receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 1000,
},
});

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

let filename = `./recordings/${Date.now()}.ogg`;

let out = createWriteStream(filename);

console.log(`šŸ‘‚ Started recording ${filename}`);

pipeline(opusStream, oggStream, out, (err) => {
if (err) {
console.warn(`āŒ Error recording file ${filename} - ${err.message}`);
} else {
console.log(`āœ… Recorded ${filename}`);
}
});
}
That was it thank you very much
Kiriox
KirioxOPā€¢14mo ago
@Qjuh I wanted the recording to stop when the person disconnects and not when they remain silent for too long so I replaced that
const opusStream = receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 1000,
},
});
const opusStream = receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 1000,
},
});
By that
const opusStream = receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.Manual,
// duration: 1000,
},
});
const opusStream = receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.Manual,
// duration: 1000,
},
});
Except that when I try to end opusStream using the destroy function it gives me an error and looking with IntelliSense I did not see any other functions that would be suitable, however in the description of manual it is clearly specified that it is necessary destroy it, do you have any idea how I can do it?
No description
Kiriox
KirioxOPā€¢14mo ago
@Qjuh Oh i lost the error message: āŒ Error recording file ./recordings/1697478736800.ogg - Premature close Yes and no, it is the one given in the example but on the other hand Premature closed comes from the error itself Okay but how can I do it? Ah it's good I succeeded thank you very much for your help
Want results from more Discord servers?
Add your server