【问题标题】:ffempeg discord bot pythonffmpeg 不和谐机器人 python
【发布时间】:2021-07-11 12:44:42
【问题描述】:

所以我想在我的不和谐语音频道中播放本地文件,现在它加入了语音频道,但它不播放任何东西。这是代码:

if message.content.startswith('$Hest'):
    where = message.content.split(" ")[1]
    channel = get(message.guild.channels, name=where)
    voicechannel = await channel.connect()
    voicechannel.play(discord.FFempegPCMAudio(executable='D:/ffmpeg/ffmpeg/bin/ffplay.exe', source='D:/ffmpeg/Horse.mp3'))

当我尝试这样做时,这是我的输出

Traceback (most recent call last):
  File "F:\Apanda\CustomMultiPyBot\venv\lib\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "F:/Apanda/CustomMultiPyBot/main.py", line 41, in on_message
    voicechannel.play(discord.FFempegPCMAudio(executable='D:/ffmpeg/ffmpeg/bin/ffplay.exe', source='D:/ffmpeg/Horse.mp3'))
AttributeError: module 'discord' has no attribute 'FFempegPCMAudio'

【问题讨论】:

  • 请注意:我建议使用discord.ext.commands framework 而不是message.content.startswith(),因为这通常是更好的做法。
  • 感谢您的建议 :)

标签: python discord discord.py


【解决方案1】:

这个问题只是你试图使用discord.FFempegPCMAudio,而类实际上是discord.FFmpegPCMAudio。

所以要更正您的代码:

if message.content.startswith('$Hest'):
    where = message.content.split(" ")[1]
    channel = get(message.guild.channels, name=where)
    voicechannel = await channel.connect()
    voicechannel.play(
        discord.FFmpegPCMAudio(
            'D:/ffmpeg/Horse.mp3',
            executable='D:/ffmpeg/ffmpeg/bin/ffplay.exe' 
        )
    )

如果您想重组它以使用discord.ext.commands framework,您的代码将如下所示:

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix="$")

@bot.command(name="Hest")
async def hest(ctx, where):
    channel = discord.utils.get(ctx.guild.channels, name=where)
    voicechannel = await channel.connect()
    voicechannel.play(
        discord.FFmpegPCMAudio(
            'D:/ffmpeg/Horse.mp3',
            executable='D:/ffmpeg/ffmpeg/bin/ffplay.exe' 
        )
    )

bot.run("<token>")

【讨论】:

  • 哇,谢谢你,我真的把我看瞎了,非常感谢!
猜你喜欢
  • 2021-10-30
  • 2021-05-27
  • 2021-07-15
  • 2021-03-29
  • 2021-03-25
  • 2018-08-13
  • 1970-01-01
  • 2021-09-30
  • 2021-02-28
相关资源
最近更新 更多