Installation
"Voice" fait référence à la capacité des bots Discord à envoyer de l'audio dans les canaux vocaux. Ceci est supporté dans discord.js via @discordjs/voice, une bibliothèque autonome créée par les développeurs de discord.js. Bien que vous puissiez l'utiliser avec n'importe quelle bibliothèque de l'API Discord Node.js, ce guide se concentrera sur l'utilisation avec discord.js.
Installation
Préalables
Pour ajouter la fonctionnalité vocale à votre bot discord.js, vous aurez besoin du paquet @discordjs/voice. Si votre système ne supporte pas aes-256-gcm, vous avez également besoin de l'un des paquets de chiffrement listés ci-dessous. Par exemple :
You can verify aes-256-gcm support by running require('node:crypto').getCiphers().includes('aes-256-gcm').
npm install @discordjs/voiceAprès cela, vous pourrez lire des fichiers Ogg et WebM Opus sans aucune autre dépendance. Si vous voulez lire de l'audio d'autres sources, ou si vous voulez améliorer les performances, envisagez d'installer certaines des dépendances supplémentaires listées ci-dessous.
Ce guide suppose que vous avez installé au moins FFmpeg pour que tous les exemples fonctionnent. Vous pouvez trouver plus d'informations sur les dépendances supplémentaires dans la section suivante.
Dépendances supplémentaires
Opus encoding
@discordjs/opus(best performance)opusscript
FFmpeg – allows you to play a range of media (e.g. MP3s).
ffmpeg- install and add to your system environmentffmpeg-static- to install FFmpeg via npm
Encryption libraries
You only need to install one of these libraries if your system does not support aes-256-gcm. You can verify this by
running require('node:crypto').getCiphers().includes('aes-256-gcm')
sodium-nativesodium(best performance)@stablelib/xchacha20poly1305@noble/cipherslibsodium-wrappers
DAVE Protocol Support
@snazzah/davey- to enable end-to-end encryption with the DAVE protocol.
Some Discord clients already require the DAVE protocol for end-to-end encryption in voice chat. Ensure you have
@snazzah/davey installed to avoid compatibility issues.
If you are facing issues when installing these dependencies, make sure you ticked the box to install optional build
tools when installing Node.js or try manually installing build tools and python: sh winget install "Visual Studio Community 2022" --override "--add Microsoft.VisualStudio.Workload.NativeDesktop " -s msstore
Debugging Dependencies
The library includes a helper function that helps you to find out which dependencies you've successfully installed. This information is also very helpful if you ever need to submit an issue on the @discordjs/voice issue tracker.
const { generateDependencyReport } = require('@discordjs/voice');
console.log(generateDependencyReport());
/*
--------------------------------------------------
Core Dependencies
- @discordjs/voice: 0.3.1
- prism-media: 1.2.9
Opus Libraries
- @discordjs/opus: 0.5.3
- opusscript: not found
Encryption Libraries
- sodium: 3.0.2
- libsodium-wrappers: not found
- tweetnacl: not found
FFmpeg
- version: 4.2.4-1ubuntu0.1
- libopus: yes
DAVE Protocol
- @snazzah/davey: 0.1.6
--------------------------------------------------
*/- Core Dependencies
- These are dependencies that should definitely be available.
- Opus Libraries
- If you want to play audio from many different file types, or alter volume in real-time, you will need to have one of these.
- Encryption Libraries
- You should have at least one encryption library installed to use
@discordjs/voice.
- You should have at least one encryption library installed to use
- FFmpeg
- If you want to play audio from many different file types, you will need to have FFmpeg installed.
- If
libopusis enabled, you will be able to benefit from increased performance if real-time volume alteration is disabled.
- DAVE Protocol
- Required for enabling end-to-end encryption in voice channels.