本文介紹了discord.js 不播放音頻文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試播放音頻文件,但由于某種原因它沒有播放任何內容,它在機器人連接后立即觸發 end
事件而不是 start
事件到語音頻道.
I am trying to play an audio file but, for some reason it's not playing anything, it's firing end
event instead of start
event, right after the bot is connected to voice channel.
client.on('message', message => {
if(message.content.startsWith('!play')) {
if(!message.member.voiceChannel) return message.channel.send('connect to voice channel first');
message.member.voiceChannel.join()
.then(connection => {
console.log("Joined voice channel!");
const dispatcher = connection.playFile(require("path").join(__dirname, './myfile.mp3'));
dispatcher.on('start', () => { //not working
dispatcher.setVolume(0.70);
console.log("Playing");
});
dispatcher.on('error', (err) => console.log(err)); //no errors
dispatcher.on('end', end => { //working fine
console.log("Finished");
console.log("End: " + end);
message.member.voiceChannel.leave()
});
});
}});
推薦答案
我從 node-modules
中刪除了 ffmpeg-binaries
并安裝了 ffmpeg
使用 sudo apt
現在工作正常.問題是,我安裝了這兩個庫.
I removed ffmpeg-binaries
from node-modules
and installed ffmpeg
using sudo apt
and it's working fine now. The problem was that, i had both of these libraries installed.
這篇關于discord.js 不播放音頻文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!