我想创建一个Discord机器人,当嵌入的消息包含某个关键字时,它会ping某个用户角色。为了避免在发布多条带有关键字的嵌入消息时ping垃圾邮件,我希望机器人ping一次,然后暂停X秒,如果有新消息,则对其做出反应,然后重复该过程。
在python中,您必须导入Time模块,然后使用Time.sleep((.
导入时间
time.sleep(x秒数(
import asyncio
,用于使程序睡眠上述时间
代码中:
@client.event
async def on_message(message):
#do your stuff here
await asyncio.sleep(10) #10 is time in seconds
#process after waiting