首页 > 解决方案 > Discord js bot connection.play() 不会播放音频文件

问题描述

我今天刚刚安装/更新了所有东西。我更新了 Visual Studio 并安装了 Node js、Discord js 和 ffmpeg 音频路径。但是我不能让不和谐机器人播放音频。是的,机器人仍然连接到呼叫,并且具有相同设置的其他脚本也工作得很好。但这似乎不起作用。我有以下控制台行“console.log(connection.play);” 在控制台中有以下输出。一切似乎都应该起作用,但事实并非如此。

以下是我的代码。

    module.exports = {
    name: 'rickroll',
    description: "never gonna give you up",
    execute(message, args) {
        if (isReady) {
            isReady = false;
            var voiceChannel = message.member.voice.channel;
            console.log('isReady: ' + isReady)
            if (!voiceChannel) {
                return message.reply("You are not in a voice channel");
            }
            voiceChannel.join().then(connection => {
                const dispatcher = connection.play('/discordBot/Rick.mp3', { volume: 0.5 });
                console.log(connection.play);

                console.log('currently playing!');
                dispatcher.on("end", end => {
                    voiceChannel.leave();
                    isReady = true;
                    message.channel.send("The bot is done!");
                });
            }).catch(error => console.log(error));
        }
    }
}

如果它看起来很乱也很抱歉,今天是我写java脚本的第一天。

标签: javascript

解决方案


推荐阅读