Мой бот Discord подключается к каналу, а состояние аудиоплеерна «играет», но аудио -ресурс нулевой, даже если он правильно маршрутизируется на пути. < /p>
async execute(interaction) {
const audioPath = path.join(__dirname, '../../../content/music/1.ogg');
// Check if the audio file exists
if (!fs.existsSync(audioPath)) {
console.error(`Audio file not found: ${audioPath}`);
return await interaction.reply({ content: '❌ Audio file not found.', ephemeral: true });
}
// Error Handles
console.log(`User ${interaction.user.tag} requested to play the default song.`);
const voiceChannel = interaction.member.voice.channel;
if (!voiceChannel) return await interaction.reply({ content: '❌ You must be in a voice channel to use this command.', ephemeral: true });
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator
});
const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
}
});
const resource = createAudioResource(audioPath, {
inputType: StreamType.Opus
});;
console.log(`Audio file path: ${audioPath}`);
console.log(`Resource metadata: ${resource.metadata}`);
console.log(`Resource type: ${resource.inputType}`);
console.log(`Resource stream: ${resource.readableStream}`);
console.log(`Resource duration: ${resource.playbackDuration}`);
console.log(`Resource volume: ${resource.volume}`);
console.log(`Resource bitrate: ${resource.bitrate}`);
player.play(resource);
connection.subscribe(player);
connection.on('stateChange', (oldState, newState) => {
console.log(`Connection transitioned from ${oldState.status} to ${newState.status}`);
});
player.on('stateChange', (oldState, newState) => {
console.log(`Audio player transitioned from ${oldState.status} to ${newState.status}`);
});
player.on(AudioPlayerStatus.Idle, () => {
console.log('🔇 Playback finished, destroying connection.');
connection.destroy();
});
await interaction.reply(`🎵 Now playing default track: Girls Wanna Have Fun Remix`);
}
};
< /code>
Это то, на что выглядит вывод консоли: < /p>
User himay requested to play the default song.
Audio file path: C:\Users\himay\Documents\Github\RADEC\content\music\1.ogg
Resource metadata: null
Resource type: undefined
Resource stream: undefined
Resource duration: 0
Resource volume: undefined
Resource bitrate: undefined
Audio player transitioned from buffering to playing
Audio player transitioned from playing to idle
🔇 Playback finished, destroying connection.
Connection transitioned from signalling to destroyed
На основе этого я могу сделать вывод, что существует проблема с тем, что аудио -ресурс не захватывается правильно, но я не уверен, что я делаю неправильно.
Мой бот Discord подключается к каналу, а состояние аудиоплеерна «играет», но аудио -ресурс нулевой, даже если он правильно маршрутизируется на пути. < /p> [code] async execute(interaction) { const audioPath = path.join(__dirname, '../../../content/music/1.ogg'); // Check if the audio file exists if (!fs.existsSync(audioPath)) { console.error(`Audio file not found: ${audioPath}`); return await interaction.reply({ content: '❌ Audio file not found.', ephemeral: true }); } // Error Handles console.log(`User ${interaction.user.tag} requested to play the default song.`); const voiceChannel = interaction.member.voice.channel; if (!voiceChannel) return await interaction.reply({ content: '❌ You must be in a voice channel to use this command.', ephemeral: true });
await interaction.reply(`🎵 Now playing default track: Girls Wanna Have Fun Remix`); } }; < /code> Это то, на что выглядит вывод консоли: < /p> User himay requested to play the default song. Audio file path: C:\Users\himay\Documents\Github\RADEC\content\music\1.ogg Resource metadata: null Resource type: undefined Resource stream: undefined Resource duration: 0 Resource volume: undefined Resource bitrate: undefined Audio player transitioned from buffering to playing Audio player transitioned from playing to idle 🔇 Playback finished, destroying connection. Connection transitioned from signalling to destroyed [/code] На основе этого я могу сделать вывод, что существует проблема с тем, что аудио -ресурс не захватывается правильно, но я не уверен, что я делаю неправильно.