python 倒计时运行程序怎么关闭_如何在Python Discord Bot中发出停止倒计时的命令?...

我想让它停止,我的意思是一个单独的命令(~cdstop)会取消倒计时。在import discord

import asyncio

counter_channel = None

async def ex(args, message, client, invoke):

global counter_channel

if counter_channel is not None:

await client.send_message(message.channel, embed=discord.Embed(color=discord.Color.red(), "There is a counter in {}".format(counter_channel.mention)))

return

counter_channel = message.channel

await client.send_message(message.channel, "5 Minutes")

await asyncio.sleep(60)

await client.send_message(message.channel, "4 Minutes")

await asyncio.sleep(60)

await client.send_message(message.channel, "3 Minutes")

await asyncio.sleep(60)

await client.send_message(message.channel, "2 Minutes")

await asyncio.sleep(60)

await client.send_message(message.channel, "1 Minutes")

await asyncio.sleep(30)

await client.send_message(message.channel, "30 Seconds")

await asyncio.sleep(15)

await client.send_message(message.channel, "15 Seconds")

await asyncio.sleep(10)

await client.send_message(message.channel, "5 Seconds")

counter_channel = None

我的想法是,在每个print语句之后,它会检查用户是否输入了~cdstop,然后从函数中中断。我认为它会起作用,但我不知道它是否有效,因为我知道它会扰乱双倒计时的检查。在

编辑

调用文件的代码:

^{pr2}$

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值