【发布时间】:2019-06-18 22:34:47
【问题描述】:
后台任务在下面这段代码中没有运行。
global bt2
bt2='False'
bot = commands.Bot(command_prefix=!)
@bot.command(pass_context=True)
async def autopurge(ctx,time):
global bt2, bt2_time, bt2_chid
bt2='True'
if int(time)==0:
bt2='False'
bt2_time=int(time)
bt2_chid=ctx.message.channel.id
async def background_task_2():
global bt2, bt2_time, bt2_chid
print(bt2, bt2_time, bt2_chid)
async for msg in bot.logs_from(bt2_chid):
await bot.delete_message(msg)
await asyncio.sleep(bt2_time)
while bt2=='True':
bot.loop.create_task(background_task_2())
它不会删除任何东西。我希望它每隔几秒钟删除一次频道中的消息。
【问题讨论】:
-
您能解释一下您预计会发生什么以及目前正在发生什么吗?需要满足什么条件?
标签: python python-3.x discord discord.py