【问题标题】:ffmpeg failing when using discord.py使用 discord.py 时 ffmpeg 失败
【发布时间】:2021-06-30 08:17:38
【问题描述】:

我正在制作一个具有 rickrolling 功能的机器人。涉及到ffmpeg,但是总是报如下错误:

FFmpeg version SVN-r18639, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: --enable-memalign-hack --enable-postproc --enable-gpl --enable-libfaac --enable-libfaad --enable-libgsm --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libx264 --enable-libxvid --disable-ffserver --enable-avisynth --enable-pthreads
  libavutil     50. 3. 0 / 50. 3. 0
  libavcodec    52.27. 0 / 52.27. 0
  libavformat   52.32. 0 / 52.32. 0
  libavdevice   52. 2. 0 / 52. 2. 0
  libswscale     0. 7. 1 /  0. 7. 1
  libpostproc   51. 2. 0 / 51. 2. 0
  built on Apr 21 2009 13:44:38, gcc: 4.2.4 (TDM-1 for MinGW)
Input #0, mp3, from 'rick.mp3':
  Duration: 00:03:33.10, start: 0.000000, bitrate: 192 kb/s
    Stream #0.0: Audio: mp3, 44100 Hz, stereo, s16, 192 kb/s
Expected number for loglevel but found: warning

即使我切换到不同的文件,它仍然会出现此错误,我做错了什么吗?我在 Windows python 3.8.2,discord.py 1.6.0 上。这是代码部分:

@bot.command(name="rickroll")
async def rick(ctx, channel: discord.VoiceChannel):
    connection = await channel.connect()
    connection.play(discord.FFmpegPCMAudio("rick.mp3", executable="ffmpeg.exe"))

【问题讨论】:

    标签: python ffmpeg discord.py


    【解决方案1】:

    确保您已将 FFmpeg 添加到 PATH 环境变量中。您可以找到有关如何执行此操作的信息here

    要连接到语音频道,您需要传入频道的 ID,因为您无法在 Discord 中提及它。

    import discord
    from discord.ext import commands
    
    voiceChannel = discord.utils.get(ctx.guild.voice_channels, id=channel)
    await voiceChannel.connect()
    

    现在我们需要与语音客户端建立连接

    connection = discord.utils.get(bot.voice_clients, guild=ctx.guild)
    

    所以最终的代码是这样的

    import discord
    from discord.ext import commands
    
    @bot.command(name="rickroll")
    async def rick(ctx, channel: int):
        voiceChannel = discord.utils.get(ctx.guild.voice_channels, id=channel)
        await voiceChannel.connect()
        connection = discord.utils.get(bot.voice_clients, guild=ctx.guild)
    
        connection.play(discord.FFmpegPCMAudio("rick.mp3"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-13
      • 1970-01-01
      • 2017-11-26
      • 2018-01-09
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多