在体验系统中为 on_message 应用冷却时间

时间:2021-03-13 17:03:40

标签: discord.py

在下面的示例中,我试图为用户发送的消息制作一张 CD,因为我不希望他们只是通过垃圾邮件到达顶部。我想不出比 datetime 和 timedelta 更好的方法,但我收到了 TypeError: fromisoformat: argument must be str 的错误。当我检查 DB 值时,它被标记并且是一个字符串。因此,我不确定我到底做错了什么。

    @commands.Cog.listener()
    async def on_message(self, message):
        if message.channel.id in talk_channels:
            stats = leveling.find_one({"id" : message.author.id})
            xp_lock = leveling.find_one({"xplock" : (datetime.utcnow()+timedelta(seconds=60)).isoformat()})
            if not message.author.bot:
                if stats is None:
                    newuser = {"id" : message.author.id, "xp" : 100, "xplock" : (datetime.utcnow()+timedelta(seconds=60)).isoformat()}
                    leveling.insert_one(newuser)
                else:
                    if datetime.utcnow() > datetime.fromisoformat(xp_lock):
                        xp = stats["xp"] + 5
                        leveling.update_one({"id":message.author.id}, {"$set":{"xp":xp}})
                        lvl = 0

0 个答案:

没有答案