【问题标题】:Discord.js - Audio Resource not playing with no errorsDiscord.js - 音频资源无法正常播放
【发布时间】:2023-03-05 08:05:01
【问题描述】:

机器人进入并表现得像它在说话/播放它但不是它甚至没有给出错误,运行文件的代码如下:

module.exports = {
    name: 'play',
    description: 'gets bots playing thing',
    execute(client, message, args, discord){
        // Make sure person who did command is in a voice channel
        const vc = message.member.voice.channel;
        if(!vc) return message.reply('You must be in a voice channel to play music!');

        // Join the voice channel
        vc.join();

        // Start Playing Audio
        const { createAudioPlayer, NoSubscriberBehavior } = require('@discordjs/voice');

        const player = createAudioPlayer({
            behaviors: {
                noSubscriber: NoSubscriberBehavior.Pause,
            },
        });

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

        const resource = createAudioResource('../audio/sound.mp3');

        player.play(resource);

        player.on('error', error => {
            console.error(`Error: ${error.message} with resource ${error.resource.metadata.title}`);
            player.play(getNextResource());
        });
    }
}

【问题讨论】:

  • 我认为使用path 模块可能会起作用。测试一下,告诉我会发生什么
  • 你的意思只是添加, const path = require('path');如果是这样,我已经尝试过了,但什么也没发生
  • 您能否确认您已安装必要的音频编解码器?如果机器人无法对音频流进行编码,则往往会发生这种情况。
  • 是的,我已经安装了 ffmpeg-static,discordjs/voice

标签: discord discord.js bots


【解决方案1】:

有几件事可能会导致您的问题。

首先,检查您是否已将 GUILD_VOICE_STATES 意图添加到您的客户端。如果没有这个,您的机器人将无法播放音频,并且会表现出您所描述的确切行为。

如果这不是问题,那么我建议的下一个最佳方法是使用 path.resolve 将 .mp3 文件的路径设为绝对路径。有时,拥有相对路径会给您的播放器带来问题。

最后,Discord.js/voice 提供了一种在 generateDependecyReport() 函数中调试依赖项的好方法。请务必检查您是否拥有最新版本的库,以及是否拥有语音功能所需的所有类型的库之一。

【讨论】:

    猜你喜欢
    • 2017-12-28
    • 2021-05-07
    • 2016-09-04
    • 1970-01-01
    • 1970-01-01
    • 2021-09-23
    • 1970-01-01
    • 1970-01-01
    • 2020-02-11
    相关资源
    最近更新 更多