NodeJS 播放AudioPlayerStatus时,Discord.js声音不播放音频

8ljdwjyq  于 2023-03-01  发布在  Node.js
关注(0)|答案(1)|浏览(162)

我似乎不明白为什么我的机器人不播放音频。我已经安装了所有必要的依赖项,下面是依赖项日志和代码。如果是音频文件,我尝试了不同的路径和youtube链接,似乎没有什么工作。
代码块被确认运行,因为控制台日志,但没有音频通过。机器人加入vc没有问题。

Core Dependencies
- @discordjs/voice: 0.14.0
- prism-media: 1.3.4

Opus Libraries
- @discordjs/opus: 0.8.0
- opusscript: 0.0.8

Encryption Libraries
- sodium-native: 4.0.1
- libsodium-wrappers: 0.7.11
- tweetnacl: not found

FFmpeg
- version: 5.0.1-essentials_build-www.gyan.dev
- libopus: yes

下面的voiceStateUpdate.js事件文件

const { Events } = require('discord.js');
const { joinVoiceChannel, AudioPlayerStatus } = require('@discordjs/voice');



module.exports = {
    name: Events.VoiceStateUpdate,
    async execute(oldState, newState) {

        //Check if muting / unmuting
        //Check if deafening / undeafening
        //Check if channel Id is null i.e. if I'm leaving not arriving
        if (newState.selfMute == oldState.selfMute && newState.selfDeaf == oldState.selfDeaf && newState.channelId != null && newState.member.user.id == '188765194246291468'){
            console.log("Syan has entered");

            const fs = require('node:fs');
            const path = require('node:path');

            const seinPath = path.join(__dirname, '../seinfeld_bites');
            const seinFiles = fs.readdirSync(seinPath).filter(file => file.endsWith('.mp3'));

            const { createAudioResource } = require('@discordjs/voice');

            //const { generateDependencyReport } = require('@discordjs/voice');

            const connection = joinVoiceChannel({
                channelId: newState.channelId,
                guildId: newState.guild.id,
                adapterCreator: newState.guild.voiceAdapterCreator,
            });

            const { createAudioPlayer } = require('@discordjs/voice');

            const player = createAudioPlayer();

            const resource = createAudioResource(seinFiles[1]);
            player.play(resource);
            connection.subscribe(player);

            player.on(AudioPlayerStatus.Playing, () => {
                console.log('Playing');
            })

            //console.log(generateDependencyReport());

            //console.log(connection);
        }

    },
};

我已经检查了所有的依赖项,尝试了不同的音频资源,并在不同的服务器上进行了尝试。任何帮助都将是美妙的。我有GUILD_VOICE_STATES在我的index.js和机器人加入vc,所以我不认为它可能是。

kr98yfug

kr98yfug1#

我为任何想知道的人想通了。这与createAudioResource()路径有关。如果你遇到这个问题,我会试着把音频文件和文件放在同一个文件夹中,然后测试它是否运行。

相关问题