我有一个简单的discord.py机器人,它可以计算用户想要的任何数字。到目前为止,该命令如下所示:
@bot.command()
async def count(ctx, startNum, endNum):
startNum = int(startNum)
endNum = int(endNum)
currentNum = startNum
if startNum > endNum:
await ctx.send("nice try, i'm not counting backwards")
while currentNum < (endNum + 1) or startNum < endNum:
await ctx.send(ctx.message.author.name + ": " + str(currentNum))
currentNum += 1
await ctx.send(ctx.message.author.mention + " I've finished counting to " + str(endNum))
假设您运行count 10
,它将显示
username: 1
username: 2
username: 3
...
username: 10
我想创建一个命令,它几乎允许用户取消一个特定计数器,而不是任何其他计数器
每个计数器最好显示一个单独的计数器ID,然后可以使用类似cancel ID
的命令取消。它看起来有点像:
> count 1 50
CounterID: 1
CounterID: 2
CounterID: 3
> cancel CounterID
CounterID has been cancelled
这怎么可能呢
在while循环中,可以添加超时1秒的
wait_for
事件:尽管该示例不允许取消特定计数器(用户自己的计数器除外)。如果您有一些数据库(如json、sqlite、mongodb等),您可能会存储每个用户的当前计数器ID
参考文献:
相关问题 更多 >
编程相关推荐