【问题标题】:How to add a pause between a discord.py bot joining a voice-channel?如何在 discord.py 机器人加入语音通道之间添加暂停?
【发布时间】:2019-12-11 01:55:23
【问题描述】:

我正在使用 discord.py 制作一个不和谐的机器人。机器人应该加入 VC 并等待 5 分钟,然后离开。出于测试目的,此数字已设置为 2 秒。现在的问题是,当机器人加入时,等待功能被完全忽略。不管我把它设置成什么。

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

#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 秒后离开。当代码按原样运行时,我没有收到任何错误消息。

【问题讨论】:

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


    【解决方案1】:

    time.sleep 不适用于 asyncio,discord.py 是在 asyncio 上使用的。请改用await asyncio.sleep(3)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-30
      • 2020-10-04
      • 2020-12-30
      • 1970-01-01
      • 2022-01-04
      • 1970-01-01
      • 1970-01-01
      • 2023-02-25
      相关资源
      最近更新 更多