【发布时间】:2020-06-06 06:00:04
【问题描述】:
我是 Discord.js 的新手,我正在尝试让机器人加入语音频道并在我的计算机上播放音频文件。我一直在关注本指南:https://discord.js.org/#/docs/main/stable/topics/voice。这是 Index.js 页面:
Colesbot.on('message', message=>{
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 => {
message.reply('I have successfully connected to the channel!');
// To play a file, we need to give an absolute path to it
const dispatcher = connection.playFile('C:\Users\bobal\Documents\GitHub\Spotify-Playlist-Discord-bot\Assets\Glory.mp3');
dispatcher.on('end', () => {
// The song has finished
console.log('Finished playing!');
});
dispatcher.on('error', e => {
// Catch any errors that may arise
console.log(e);
});
dispatcher.setVolume(0.5); // Set the volume to 50%
}).catch(console.log);
} else {
message.reply('You need to join a voice channel first!');
}
}
});
exports.run = (client, message, args) => {
let user = message.mentions.users.first || message.author;
}
FFMPEG 已安装,我已为其设置环境路径。当我在命令行中输入 FFMPEG 时,我得到了正确的响应。
有人说我需要安装 ffmpeg 二进制文件,但是当我运行 npm install ffmpeg-binaries 时,我收到一条错误消息 that is here
然后我尝试安装旧版本,我现在使用的是 ffmpeg-binaries@3.2.2-3 但是当我输入 /join 时出现错误
[ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received type object
【问题讨论】:
-
...是的,用不和谐的机器人播放音乐是一种痛苦...我做了一个从 youtube 上播放,它有一半的时间和特定的 url 工作...对不起,我无能为力很多,也许你可以检查我的代码github.com/gui3/discord-sandbot/blob/master/commands/play.js
-
你在 bot 服务器上安装了 ffmpeg 二进制文件吗?
-
我已经在我的 PC 上正确安装了 ffmpeg,但是当我尝试在我的项目文件夹中运行此命令时:npm install ffmpeg-binaries 我收到一条巨大的错误消息。你想让我在我的问题中发布错误消息吗?
标签: node.js ffmpeg discord.js dispatcher