【发布时间】:2020-07-24 20:59:40
【问题描述】:
我正在使用discord.py 制作一个不和谐机器人。我想发出一个命令,每 100 秒清除一次频道内的所有消息。这是我的代码:
autodeletetime = -100
autodeletelasttime = 1
@client.command()
@commands.has_permissions(manage_messages=True)
async def autodelete(ctx):
global autodeleterunning
if autodeleterunning == False:
autodeleterunning = True
asgas = True
while asgas:
message = await ctx.send(f'All messages gonna be deleted in 100 seconds')
await message.pin()
for c in range(autodeletetime,autodeletelasttime):
okfe = abs(c)
await message.edit(content=f"All messages gonna be deleted in {okfe} seconds" )
await asyncio.sleep(1)
if c == 0:
await ctx.channel.purge(limit=9999999999999999999999999999999999999999999999999999999999999999999)
await time.sleep(1)
autodeleterunning = False
else:
await ctx.send(f'The autodelete command is already running in this server')
我希望循环在清除完成后每 100 秒重新启动一次。
【问题讨论】:
标签: python python-3.x discord.py