【问题标题】:Discord Bot Not Playing Audio discord.js v13Discord Bot 不播放音频 discord.js v13
【发布时间】:2021-11-18 11:35:00
【问题描述】:

我正在尝试制作一个可以在语音频道中播放 mp3 文件的 discord 机器人.. 但它似乎没有按预期工作


            connection = joinVoiceChannel({
                channelId: voice.channelId,
                guildId: interaction.guildId,
                adapterCreator: voice.channel.guild.voiceAdapterCreator,
            });
            
            
            let resource = createAudioResource(createReadStream(join(__dirname, 'resources/try.mp3')), {
                inlineVolume : true
            });

            resource.volume.setVolume(0.2);

            console.log(join(__dirname, 'resources/try.mp3'));
            
            const player = createAudioPlayer();

            connection.subscribe(player);
            player.play(resource)
            console.log("done");

            await interaction.reply('I have joined the voice channel!');

成功加入语音频道,但根本不播放任何声音

The bot joined the voice channel

我已通过 console.logging join(__dirname, 'resources/try.mp3') 确保目录名称正确

我还尝试检查在 discord.js v13 中播放音频所需的依赖项

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

console.log(generateDependencyReport());

这是输出:

--------------------------------------------------
Core Dependencies
- @discordjs/voice: 0.6.0
- prism-media: 1.3.2

Opus Libraries
- @discordjs/opus: 0.5.3
- opusscript: not found

Encryption Libraries
- sodium: not found
- libsodium-wrappers: 0.7.9
- tweetnacl: not found

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

我认为 discord.js v13 文档说它只需要 Core、Opus、Encryption 和 FFmpeg 依赖项中的任何一个(如果我错了,请纠正我)

我错过了什么吗?

提前谢谢你

【问题讨论】:

    标签: javascript ffmpeg discord discord.js bots


    【解决方案1】:

    发生在我身上的完全一样。问题在于您在新的 Discord.js 中设置的意图。更多内容在 reddit 线程链接中。

    https://www.reddit.com/r/Discordjs/comments/pprpit/voice_connection_stuck_in_the_signalling_state/

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    【解决方案2】:

    谢谢,成功了!

    我实际上并没有在我的问题中显示这一行:

    我变了

    const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
    

    到:

    const myIntents = new Intents();
    myIntents.add(Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_VOICE_STATES);
    
    const client = new Client({ intents: myIntents });
    

    它现在按预期播放声音

    Bot plays sound

    【讨论】:

      猜你喜欢
      • 2022-01-20
      • 1970-01-01
      • 2018-05-17
      • 2021-10-29
      • 2017-03-05
      • 2021-11-07
      • 2020-11-26
      • 2021-12-04
      • 2020-02-11
      相关资源
      最近更新 更多