【问题标题】:Discordjs v13.1 bot not playing sound with mp3 fileDiscordjs v13.1 bot 不使用 mp3 文件播放声音
【发布时间】:2021-11-05 09:52:42
【问题描述】:

在我的机器人播放 mp3 文件时需要一些帮助。我的机器人成功加入语音聊天,播放时长与文件长度相同,但没有播放音频。机器人图标确实亮绿色,但没有声音。

这是代码

    await entersState(voiceConn, VoiceConnectionStatus.Ready, 10e3)
    const player = createAudioPlayer()
    player.on('debug', m => {
      console.log(m)
    })
    player.on('error', error => {
      console.error(`Error: ${error}`)
    })

    const resource = createAudioResource(join(__dirname, '../../songs/song.mp3'))

    player.play(resource)
    player.on(AudioPlayerStatus.Playing, () => {
      console.log('Now playing')
    })

    voiceConn.subscribe(player)

    await interaction.followUp('Playing!')
    await entersState(player, AudioPlayerStatus.Idle, 10e3)
    voiceConn.destroy()

这是玩家的日志

from {"status":"idle","resource":false,"stepTimeout":false}
to {"status":"buffering","resource":true,"stepTimeout":false}
Now playing
state change:
from {"status":"buffering","resource":true,"stepTimeout":false}
to {"status":"playing","missedFrames":0,"playbackDuration":0,"resource":true,"stepTimeout":false}
state change:
from {"status":"playing","missedFrames":0,"playbackDuration":8700,"resource":true,"stepTimeout":false}
to {"status":"idle","resource":false,"stepTimeout":false}

【问题讨论】:

    标签: typescript discord.js


    【解决方案1】:

    您是否尝试过使用可读流作为音频资源的输入?

    const resource = createAudioResource(fs.createReadStream(join(__dirname, '../../songs/song.mp3')));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-07
      • 1970-01-01
      • 2021-11-07
      相关资源
      最近更新 更多