【发布时间】:2023-03-05 08:05:01
【问题描述】:
机器人进入并表现得像它在说话/播放它但不是它甚至没有给出错误,运行文件的代码如下:
module.exports = {
name: 'play',
description: 'gets bots playing thing',
execute(client, message, args, discord){
// Make sure person who did command is in a voice channel
const vc = message.member.voice.channel;
if(!vc) return message.reply('You must be in a voice channel to play music!');
// Join the voice channel
vc.join();
// Start Playing Audio
const { createAudioPlayer, NoSubscriberBehavior } = require('@discordjs/voice');
const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Pause,
},
});
const { createAudioResource } = require('@discordjs/voice');
const resource = createAudioResource('../audio/sound.mp3');
player.play(resource);
player.on('error', error => {
console.error(`Error: ${error.message} with resource ${error.resource.metadata.title}`);
player.play(getNextResource());
});
}
}
【问题讨论】:
-
我认为使用
path模块可能会起作用。测试一下,告诉我会发生什么 -
你的意思只是添加, const path = require('path');如果是这样,我已经尝试过了,但什么也没发生
-
您能否确认您已安装必要的音频编解码器?如果机器人无法对音频流进行编码,则往往会发生这种情况。
-
是的,我已经安装了 ffmpeg-static,discordjs/voice
标签: discord discord.js bots