【问题标题】:How do i get my discord bot to play an audio file from my computer如何让我的不和谐机器人从我的电脑播放音频文件
【发布时间】:2023-03-18 05:14:02
【问题描述】:

我正在尝试让我的机器人在语音聊天中播放音频文件,而不是 youtube 视频。令人惊讶的是,我真的找不到任何有用的帮助。


@client.command()
async def play(ctx, *args):
    if len(args) == 0:
        await ctx.send("Specify something then")
    else:
        #server = ctx.message.server
        #voice_client = client.voice_client_in(server)

        voice_player = await ctx.message.author.voice.channel.connect()

        if args[0] == "chulp":
            print("Playing chulp")
            source = discord.FFmpegPCMAudio("Core files\\Sounds\\chulpy.mp3")
            player = voice_player.play(source)
            player.start()

我总是收到这个错误:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'start'

【问题讨论】:

  • play 不返回任何内容,它应该只是开始播放文件。如果删除player.start() 行,会发生什么?
  • 它不会改变任何东西

标签: python-3.x voice discord.py-rewrite


【解决方案1】:

你做错了。你必须这样做 -

if args[0] == "chulp":
    print("Playing chulp")
    player = voice_player.create_ffmpeg_player("Core files\\Sounds\\chulpy.mp3")
    player.start()

我不确定,但这也可以 -

if args[0] == "chulp":
    print("Playing chulp")
    voice_player.play(discord.FFmpegPCMAudio("Core files\\Sounds\\chulpy.mp3"))

我认为您将来自 2 个不同来源的代码组合在一起。

【讨论】:

  • 它不工作,它甚至没有打印确认
猜你喜欢
  • 1970-01-01
  • 2021-03-16
  • 2021-11-15
  • 2018-01-02
  • 2020-12-19
  • 2023-03-10
  • 1970-01-01
  • 2021-10-01
  • 2019-05-05
相关资源
最近更新 更多