【问题标题】:Bot Radio Looping Audio discord py discord botBot Radio Looping Audio discord py discord bot
【发布时间】:2021-06-15 13:28:27
【问题描述】:

我想一遍又一遍地播放一个文件,但我得到一个错误。这是一个错误:

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

这是我的机器人不和谐代码:

@client.command()
async def p(ctx):
   await ctx.channel.purge(limit=1)
   channel = ctx.author.voice.channel
   voice = discord.utils.get(client.voice_clients, guild=ctx.guild)

   def repeat(guild, voice, audio):
       voice.play(audio, after=lambda e: repeat(guild, voice, audio))
       voice.is_playing()

   if channel and not voice.is_playing():
       audio = discord.FFmpegPCMAudio('audio.mp3')
       voice.play(audio, after=lambda e: repeat(ctx.guild, voice, audio))
       voice.is_playing() 

有什么问题?

【问题讨论】:

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


    【解决方案1】:

    试试这个:

    @client.command()
    async def p(ctx):
       await ctx.channel.purge(limit=1)
       voice = ctx.voice_client
    
       if not voice:
           return await ctx.send("You are not in a voice channel")
       
       await voice.connect()
    
       def repeat(voice, audio):
           voice.play(audio, after=lambda e: repeat(voice, audio))
           voice.is_playing()
    
       if voice and not voice.is_playing():
           audio = discord.FFmpegPCMAudio('audio.mp3')
           voice.play(audio, after=lambda e: repeat(voice, audio))
           voice.is_playing()
    

    查看您的评论后,您可以通过rejoin 命令让机器人离开并加入语音频道,这将离开语音频道并再次加入:

    @client.command()
    async def rejoin(ctx):
        voice = ctx.voice_client
        if not voice:
            return await ctx.send("You're not connected to a voice channel")
        if voice.is_connected():
            await voice.disconnect()
            await voice.connect()
        else:
            await voice.connect()
    

    【讨论】:

    • 没有报错,但是bot没有加入Voice
    • @AbolfazlRabiei 你正在使用你自己的join 命令,是吗?
    • 我希望机器人同时加入语音和游戏
    • @AbolfazlRabiei 你没有在你的问题陈述中提到这一点。无论如何,我已经编辑了我的帖子以添加它。现在,它应该加入语音频道了。
    • 谢谢,如果我想给我的机器人充耳不闻怎么办?
    猜你喜欢
    • 2021-06-04
    • 2021-02-07
    • 2021-04-24
    • 2020-08-17
    • 2021-11-10
    • 1970-01-01
    • 2021-06-17
    • 2021-04-20
    • 1970-01-01
    相关资源
    最近更新 更多