![](/img/trans.png)
[英]How do I send downloaded .mp3 with a Discord.js bot using ytdl-core?
[英]Discord bot using discord.js not playing mp3 file, no errors given
我的代碼到達第 24 行const dispatcher = connection.play('/sounds/Pigstep.mp3', { volume: 0.9 });
,我知道是因為第 26 行的console.log('audio is now playing!')
被執行。 機器人確實進入了語音頻道,但它不播放歌曲。 我在終端中沒有收到錯誤消息。
我的機器人有權加入語音頻道並講話。 我已安裝 ffmpeg 並將其添加到路徑中。
這是我的代碼:
const Discord = require('discord.js');
const auth = require('./auth.json');
const ytdl = require('ytdl-core');
const client = new Discord.Client();
client.login(auth.token);
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
console.log('Ready!');
});
client.on('message', async msg => {
if (msg.content.substring(0, 1) === '!') {
console.log('Message received!');
let args = msg.content.substring(1).split(' ');
const cmd = args[0];
args = args.splice(1);
switch (cmd) {
case 'cricket':
var connection = await msg.member.voice.channel.join();
const dispatcher = connection.play('/sounds/Pigstep.mp3', { volume: 0.9 });
dispatcher.on('start', () => {
console.log('audio is now playing!');
});
console.log('Playing!');
break;
}
}
});
在此先感謝您的幫助:)
播放需要絕對路徑。 還要確保您的代碼中有正確的文件目錄
connection.play(require("path").join(__dirname, '/sounds/Pigstep.mp3'));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.