我目前的目标是为我的私人Disord Server创建一个可以播放. mp3文件的Disord Bot。这是我的代码。文件test.mp3与.py文件位于同一文件夹中。错误消息是:“NameError:name'FFmpegPCMAudio'未定义”。我在路径环境变量中添加了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)
尝试从不和谐库导入它
from discord import FFmpegPCMAudio