You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为基于数据库的机器人命令设置冷却?重启后冷却重置问题求助

Discord经济机器人冷却重启重置问题及代码尝试

我正在开发一款经济类Discord机器人,其中包含work这类需要2-3小时冷却的命令。命令运行正常,但机器人重启或离线后冷却会重置。我尝试编写了一个检查函数,保存当前时间并添加30秒用于测试,代码如下:

@client.command()
async def ok(ctx):
    current_time = datetime.datetime.now()
    final_time = current_time + datetime.timedelta(seconds=30)
    await client.cd.upsert({"_id":ctx.author.id,"cd_time":final_time})
    await ctx.send(final_time)
@tasks.loop(seconds=30)
async def checker(self,ctx):
    ab=await client.cd.find({})
    current_time = datetime.datetime.now()
    async for a in ab:
        if current_time >= a["cd_time"]:
            await ctx.send("ok")
        else:
            await ctx.send("on cd")

checker.start()

内容的提问来源于stack exchange,提问作者Saptanshu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 23:39:57