我想让我的 Discord 机器人加入语音聊天,但每次我这样做时,我都会在日志(cmd)中收到一条错误消息,说 FFMPEG not found
,请帮助我。
错误图片:
这是代码:
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!');
}
}
});
这是我的 package.json 文件:
{
"name": "xxxtentacion",
"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
一个 opus 编码器,从下面选择一个:
npm install node-opus
(更好的性能)npm install opusscript
(良好的网络连接)
首选的 opus 引擎是 node-opus,因为它的性能明显优于 opusscript。当两者都可用时,discord.js 将自动选择 node-opus。仅建议在 node-opus 难以运行的开发环境中使用 opusscript。对于生产机器人,使用 node-opus 应该被认为是必要的,尤其是当它们要在多个服务器上运行时。
关于javascript - Discord机器人: Fix ‘FFMPEG not found’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54658125/