ffmpeg - 创建一个 Discord Bot 来播放 .mp3 文件

标签 ffmpeg discord.py discord.py-rewrite

我目前的目标是创建一个 Discord Bot,它可以为我的私有(private) Discord 服务器播放 .mp3 文件。这是我的代码。文件 test.mp3 与 .py 文件位于同一文件夹中。错误消息是:“NameError: name 'FFmpegPCMAudio' is not defined”。我在我的路径环境变量中添加了 ffmpeg 可执行文件。任何人都可以帮忙吗?

import discord
import asyncio
import time

client = discord.Client()

@client.event
async def on_message(message):
    if "test" in message.content:
        user = message.author
        voice_channel = user.voice.channel
        channel = None
        if voice_channel != None:
            channel = voice_channel.name
            vc = await voice_channel.connect()
            player = vc.play(FFmpegPCMAudio("test.mp3"), after=lambda: print('done'))
            player.start()
            while not player.is_done():
                await asyncio.sleep(1)
            player.stop()
            await vc.disconnect()

client.run(TOKEN)

最佳答案

尝试从 discord 库中导入它

 from discord import FFmpegPCMAudio

关于ffmpeg - 创建一个 Discord Bot 来播放 .mp3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65514775/

相关文章:

error-handling - 如何修复MissingPermissions错误不起作用?不和谐

FFMPEG 无法对高速变化的视频进行编码

discord.py - 如何使用discord.py删除角色?

ffmpeg - iPhone 上 Shader 将 YUV 转为 RGB

python - 在 Discord.py bot 中记录删除消息的人

python - 如何检查并等待消息下的 react ?

python - Discord.py(重写): Error Handling “Improper Token” In Function

python-3.x - 消息对象没有属性 'server'

ffmpeg - 如何用FFMPEG分块记录UDP流?

python - 如何在 python 函数中使用 ffmpeg