【问题标题】:Creating a Discord Bot to play .mp3 files创建一个 Discord Bot 来播放 .mp3 文件
【发布时间】:2021-04-07 10:02:40
【问题描述】:

我目前的目标是为我的私人 Discord 服务器创建一个可以播放 .mp3 文件的 Discord Bot。这是我的代码。文件 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)

【问题讨论】:

  • 尝试从discordfrom discord import FFmpegPCMAudio导入

标签: ffmpeg discord.py discord.py-rewrite


【解决方案1】:

尝试从 discord 库中导入它

 from discord import FFmpegPCMAudio

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    • 2020-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-17
    相关资源
    最近更新 更多