如何修复“ connection.play不是功能”?

时间:2019-02-15 13:06:09

标签: javascript discord discord.js

因此,我一直在寻找代码,并将它们全部编译成一个可以工作但不能播放音频文件的东西。所以我想做的是在不和谐频道上播放audiofile.wav。这就是我尝试过的代码。

function playFunction(arguments, receivedMessage) {
  var isReady = true;
  if (isReady = true) {
    isReady = false;
    var voiceChannel = receivedMessage.member.voiceChannel;
    var connection = voiceChannel.join();
    voiceChannel.join().then(connection=> {console.log("Test")}).catch(err => console.log(err));
    voiceChannel.join().then(connection=> {}).catch(err => console.log(err));
    const dispatcher = connection.play('./audiofile.wav');
   dispatcher.on("end", end => {voiceChannel.leave();})
  } 
}

因此,正如标题中所述,我得到的错误是:

const dispatcher = connection.play('./audiofile.wav');
                                  ^

TypeError: connection.play is not a function
    at playFunction (rootpath\bot.js:88:35)
    at processCommand (rootpath\bot.js:73:9)
    at Client.client.on (rootpath\bot.js:22:9)
    at emitOne (events.js:116:13)
    at Client.emit (events.js:211:7)
    at MessageCreateHandler.handle rootpath\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (rootpath\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:103:65)
    at WebSocketConnection.onPacket (rootpath\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
    at WebSocketConnection.onMessage (rootpath\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
    at WebSocket.onMessage (rootpath\node_modules\ws\lib\event-target.js:120:16)

根路径只是我bot.js和其他文件的路径。

1 个答案:

答案 0 :(得分:0)

该方法“ play()”在该上下文中不存在。我认为您需要使用“ playFile()”。

const dispatcher = connection.playFile('./audiofile.wav');

更多信息:https://discord.js.org/#/docs/main/stable/class/VoiceConnection?scrollTo=playFile