【问题标题】:Bot doesn't play music机器人不播放音乐
【发布时间】:2022-02-06 14:28:32
【问题描述】:
@client.event
async def on_ready(pass_context = True):
    print('logged in as {0.user}'.format(client))
    me = client.get_user(str(308330919176175616))
    tchannel = client.get_channel(931274904228233291)
    vchannel = client.get_channel(939513894001578024)
    await vchannel.connect()
    await vchannel.play(discord.FFmpegPCMAudio['музика.mp3'], pass_context = True)

AttributeError: 'VoiceChannel' 对象没有属性 'play'

更新: 我已经更改了代码,所以它没有显示错误,但仍然没有音乐。 代码:

@client.event
async def on_ready(pass_context = True):
    print('logged in as {0.user}'.format(client))
    me = client.get_user(str(308330919176175616))
    tchannel = client.get_channel(931274904228233291)
    vchannel = client.get_channel(939513894001578024)
    vc = await vchannel.connect()
    vc.play(discord.FFmpegPCMAudio('s.mp3'))

【问题讨论】:

  • 机器人是否连接到语音通道?
  • 还有为什么你一启动机器人就试图运行这个命令。制作一个单独的命令。

标签: python discord bots


【解决方案1】:

试试这个代码,而不是事先提到语音通道,让机器人找到它!我有这个有效的代码。所以试试这个!

@client.command()
async def play(ctx):
    voice_state = ctx.author.voice

    if voice_state == None:
        #user isnt in voice channel so it wont connect
        return

    if voice_state != None:
        await ctx.author.voice.channel.connect()

    vc = ctx.voice_client
    vc.play(discord.FFmpegPCMAudio('s.mp3'))

【讨论】:

    猜你喜欢
    • 2021-05-05
    • 2021-05-28
    • 2022-01-21
    • 2021-10-25
    • 2019-05-24
    • 2020-03-16
    • 2020-11-16
    • 2022-01-04
    • 2020-09-03
    相关资源
    最近更新 更多