我正在尝试创建一个播放来自mp3文件音频的discord机器人。它能够加入语音通道,甚至具有活动指示器,但是没有声音输出。我还注意到根本没有显示任何错误。
我还注意到退出频道需要很长时间。
我的代码:
static random_vc(client, vchannel){
if(vchannel==undefined){ console.log("nooo"); return; }
var path = "./";
var myfile = ["1.mp3","2.mp3","3.mp3","4.mp3","5.mp3","6.mp3","7.mp3","8.mp3","9.mp3"];
var rand = Math.random();
var i = Math.floor(rand * Math.floor(myfile.length)); //get random index from array
vchannel.join()
.then(connection => {
var dispatcher = connection.play('/path/to/bot/' + myfile[i]);
dispatcher.on("end", () => { setTimeout(function(){
console.log("exit chnl");
dispatcher.destroy();
vchannel.leave();
}, 2000) });
}).catch(console.error);
}
部分日志:
[VOICE (244101204727169025:1)]: [WS] >> {"op":1,"d":{"protocol":"udp","data":{"address":"removed","port":removed,"mode":"xsalsa20_poly1305_lite"}}}
[VOICE (244101204727169025:1)]: [UDP] << {"address":"removed","port":removed}
[VOICE (244101204727169025:1)]: [WS] << {"op":4,"d":{"video_codec":"H264","secret_key":removed,"mode":"xsalsa20_poly1305_lite","media_session_id":"removed","encodings":[{"type":"audio","ssrc":removed,"rid":"","max_bitrate":0,"active":true}],"audio_codec":"opus"}}
[VOICE (244101204727169025:0)]: [WS] >> {"op":5,"d":{"speaking":1,"delay":0,"ssrc":removed}}
[VOICE (244101204727169025:0)]: [WS] >> {"op":5,"d":{"speaking":0,"delay":0,"ssrc":removed}}
[VOICE (244101204727169025:0)]: Ready with authentication details: {"sessionID":"removed","token":"removed","endpoint":"eu-central627.discord.media","ssrc":removed,"port":removed,"modes":["aead_aes256_gcm","xsalsa20_poly1305_lite","xsalsa20_poly1305_suffix","xsalsa20_poly1305"],"ip":"removed","experiments":["bwe_conservative_link_estimate","bwe_remote_locus_client"],"mode":"xsalsa20_poly1305_lite","video_codec":"H264","secret_key":{removed},"media_session_id":"removed","encodings":[{"type":"audio","ssrc":removed,"rid":"","max_bitrate":0,"active":true}],"audio_codec":"opus"}
版本信息:node = v14.9.0,discord.js = 12.3.0