javascript Discord Bot Not Playing Audio discord.js v13

63lcw9qa  于 2023-04-19  发布在  Java
关注(0)|答案(3)|浏览(138)

我试图使一个不和谐的机器人,可以播放mp3文件在语音通道..但它似乎并不工作的意图

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文档说它只需要每个核心,Opus,加密和FFmpeg依赖项中的任何一个(如果我错了请纠正我)
我错过什么了吗?
先谢谢你了

2w2cym1i

2w2cym1i1#

谢谢,它工作了!
其实我并没有在我的问题中显示这条线:
我变了

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

iklwldmw

iklwldmw2#

我也遇到了同样的问题。问题出在你在新的Discord.js中设置的intent上。更多的问题出在reddit线程链接上。
https://www.reddit.com/r/Discordjs/comments/pprpit/voice_connection_stuck_in_the_signalling_state/

hjzp0vay

hjzp0vay3#

更新Discord.js版本14。在检查版本14文档后,我能够在版本14中使用以下内容:

const { Client, GatewayIntentBits } = require('discord.js');

const client = new Client({ intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildVoiceStates,
  ], 
});

请参阅Discordjs guide page on intents作为参考:https://discordjs.guide/popular-topics/intents.html#privileged-intents

相关问题