我安装了最新的节点ffmpeg和node-opus
if (msg.content === ('$join')) {
if (msg.member.voiceChannel) {
const connection = msg.member.voiceChannel.join();
const dispather = connection.playFile('./birthday.mp3');
dispatcher.on('end', () => connection.disconnect());
.then(connection => {
msg.reply('I have successfully connected to the channel!');
});
} else {
msg.reply('You need to join a voice channel first!');
}
}
当我自己加入语音频道并输入' $ join'它显示" playFile"因为它不是文档中的函数。
C:\ReinaBot\test2\app.js:40
const dispather = connection.playFile('./birthday.mp3');
at Client.client.on.message (C:\ReinaBot\test2\app.js:40:44)
at emitOne (events.js:116:13)
at Client.emit (events.js:211:7)
at MessageCreateHandler.handle (C:\ReinaBot\test2\node_modules\discord.js\src\client\websock
at WebSocketPacketManager.handle (C:\ReinaBot\test2\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:103:65)
at WebSocketConnection.onPacket (C:\ReinaBot\test2\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (C:\ReinaBot\test2\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
at WebSocket.onMessage (C:\ReinaBot\test2\node_modules\ws\lib\event-target.js:120:16)
at emitOne (events.js:116:13)
at WebSocket.emit (events.js:211:7)
答案 0 :(得分:0)
voiceChannel.join()
没有返回连接。它返回一个承诺
来自documentation:
// Play files natively
voiceChannel.join()
.then(connection => {
const dispatcher = connection.playFile('C:/Users/Discord/Desktop/music.mp3');
})
.catch(console.error);