如何在discord.py漫游器加入语音通道之间添加停顿?

时间:2019-08-02 12:23:27

标签: python async-await discord discord.py-rewrite

我正在用discord.py做一个discord机器人。该机器人应该加入VC,等待5分钟,然后离开。为了进行测试,此数字已设置为2秒。现在的问题是,当僵尸程序加入时,完全忽略了wait函数。不管我设置什么。

我尝试了更大的数字,但是那也不起作用。

#The part of the code I'm having trouble with:
try:
    vc = await ctx.guild.get_channel(int(chanid)).connect()
    time.sleep(2)
    await vc.disconnect()
except: 
    print(f"Action Failed: JoinVC.")
#Keep in mind, this is only part of the code.

我希望漫游器尝试加入该频道,然后2秒钟后离开。按原样运行代码时,没有任何错误消息。

1 个答案:

答案 0 :(得分:0)

time.sleep在asyncio上不能很好地工作,它对discord.py不利。尝试使用await asyncio.sleep(3)