【发布时间】:2021-11-22 10:49:54
【问题描述】:
我正在使用 discord.js v13 并尝试使用 @discordjs/voice 播放音频文件。我的问题是机器人会正确地做所有事情,但是当指示声音来自机器人的绿色圆圈出现时,我什么也听不到。我认为这不是我的耳机的音频问题,因为我可以听到其他所有声音,包括其他不和谐的人。
这是我的代码:
const { getVoiceConnection, joinVoiceChannel, AudioPlayerStatus, createAudioResource, getNextResource, createAudioPlayer, NoSubscriberBehavior } = require('@discordjs/voice');
module.exports = {
name: "play",
category: "music",
description: "plays audio",
usage: "<id | mention>",
run: async (client, message, args) => {
const voiceChannel = message.member.voice.channel;
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator
});
const audioPlayer = createAudioPlayer();
connection.subscribe(audioPlayer);
audioPlayer.play(createAudioResource('./sound/audio.mp3'));
}
}
感谢任何帮助。
【问题讨论】:
-
尝试在
audioPlayer.play(...)之前写console.log(createAudioResource('./sound/audio.mp3').readable),看看音频资源是否可以播放 -
控制台在日志上显示为true
-
嗯,试试
createAudioResource(createReadStream('./sound/audio.mp3'), { inlineVolume: true })(带&,如果不工作,不带inlineVolume : true -
解决了这个问题,谢谢
-
删除或添加 inlineVolume 会改变什么吗?
标签: javascript discord.js