首页 > 解决方案 > 为什么机器人不按时加入?

问题描述

这是我在 python 中的代码,用于不和谐机器人。我不明白为什么它没有按时加入。是如果坏了还是什么。

任何帮助表示赞赏!

async def start(ctx):
    if ctx.author.voice:
        await ctx.send('Timer has started')
        channel = ctx.message.author.voice.channel
        while True:
            time = datetime.datetime.now()
            print(str(time.minute) + " " + str(time.second))
            if time.minute == 26:
                voice = await channel.connect()
                source = FFmpegPCMAudio('sound.mp3')
                player = voice.play(source)
                tmt.sleep(72)
                await voice.disconnect()
                print('left the channel')
    else:
        print("Can't join")
        return

标签: pythondiscord.py

解决方案


我找到了解决方案。它没有连接,因为它发生得太快了。我只是time.sleep(1)在操作之前和 if 语句之后添加。现在它正在加入。感谢您的任何帮助。

编辑:我需要使用asyncio.sleep(1)而不是time.sleep(1). 因为time.sleep是越野车,会停止一切。谢谢@damaredayo


推荐阅读