错误的错误:
client.on('message', message => {
// Voice only works in guilds, if the message does not come from a guild,
// we ignore it
if (!message.guild) return;
if (message.content === '/join') {
// Only try to join the sender's voice channel if they are in one themselves
if (message.member.voiceChannel) {
message.member.voiceChannel.join()
.then(connection => { // Connection is an instance of VoiceConnection
message.reply('I have successfully connected to the channel!');
})
.catch(console.log);
} else {
message.reply('You need to join a voice channel first!');
}
}
});
这是我的软件包。JSON文件:
{
"name": "x",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js"
},
"dependencies": {
"discord.js": "^11.4.2",
"dotenv": "^6.2.0",
"ffmpeg": "0.0.4",
"opusscript": "0.0.6"
},
"devDependencies": {
"nodemon": "^1.18.9"
}
}
向语音介绍 Discord.js中的语音可用于许多事物,例如音乐机器人,录制或中继音频。在discord.js,您可以通过连接到VoiceChannel来获得语音来获取VoiceConnection,您可以在其中开始流式传输和接收音频。
ffmpeg -npm install ffmpeg-binaries
npm install node-opus
npm install opusscript
(良好的网络连接)
opus。
尽管这是独立的平台,但对于每个平台都需要不同的过程,请注意:我仅列出了我拥有专业知识的那些平台。您主要使用软件包管理器及其依赖项安装它,或者您可以使用手动编译代码的方式,并在HEREhere.中描述的步骤进行编译。
# Ubuntu / Debian / Linux Mint
sudo apt install ffmpeg
# ArchLinux / Manjaro / Anarchy
sudo pacman -S ffmpeg
# Gentoo / Funtoo
USE=opus sudo emerge ffmpeg
windows
windows并不容易,因为GNU/Linux,您要么手动满足所有依赖项,然后用MSVC独自编译所有内容,或者使用Cygwin或Msys2编译。
Zeranoe
的网站下载预编译的Windows二进制文件。bin/
文件夹的所有内容的邮政编码,这些档案是ffmpeg二进制文件。可选地,将它们存储在Path环境变量中列出的文件路径中,以简单地将其运行在shell中。
我在discord.js播放流的问题甚至以为我安装了ffmpeg,所以如果不能在cmd中单独运行cmd,这是一个可能的修复程序,至少是在Windows中进行的解决方案,然后我去了Node_modules \ Prism-Media \ SR