你如何修复 "connection.play is not a function"?
How do you fix "connection.play is not a function"?
所以,我四处寻找代码,并将所有代码编译成一个可以运行但无法播放音频文件的东西。所以我想做的是在不和谐的频道上播放 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 和其他文件的路径。
该上下文中不存在方法 "play()"。我认为你需要使用 "playFile()".
const dispatcher = connection.playFile('./audiofile.wav');
更多信息:https://discord.js.org/#/docs/main/stable/class/VoiceConnection?scrollTo=playFile
所以,我四处寻找代码,并将所有代码编译成一个可以运行但无法播放音频文件的东西。所以我想做的是在不和谐的频道上播放 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 和其他文件的路径。
该上下文中不存在方法 "play()"。我认为你需要使用 "playFile()".
const dispatcher = connection.playFile('./audiofile.wav');
更多信息:https://discord.js.org/#/docs/main/stable/class/VoiceConnection?scrollTo=playFile