discord.py on_message冷却时间

时间:2019-06-18 15:55:07

标签: python-3.x time discord.py

它实际上并没有阻止用户获得更多经验。

 @commands.Cog.listener()
    @commands.cooldown(1, 30, commands.BucketType.Member)
    async def on_message(self, message):
      global client
      exp = 0
      level = 0
      up = random.randint(1,4)
      db = client.bot
      posts = db.stats
      for x in posts.find({"userid":f"{message.author.id}"},{ "_id": 0, "userid": 0,"money":0,"shares":0}):
        level = x["level"]
        exp = x["exp"]
        print(x)
      exp = int(exp)
      level = int(level)
      up = int(up)
      exp = exp + up
      posts.update_one({"userid":f"{message.author.id}"}, {"$set": { "exp": f"{exp}" }})
      xp_start = int(exp)
      lvl_start = int(level)
      xp_end = math.floor(5 * (lvl_start ^ 2) + 50 * lvl_start + 100)
      if xp_end < xp_start:
        embed = discord.Embed(color=0xffffff)
        embed.add_field(name=f"{message.author}", value=f"Has leveled up to level {lvl_start+1}", inline=True)
        await message.channel.send(embed=embed)
        level += 1
        exp = 0
        exp = int(exp)
        level = int(level)
        posts.update_one({"userid":f"{message.author.id}"}, {"$set": { "exp": f"{exp}","level": f"{level}"}})

我希望成员在服务器上交谈并每分钟获得exp,但我将其计时30秒只是为了对其进行测试。

1 个答案:

答案 0 :(得分:0)

我认为您不能对discord.Events使用冷却时间。您应该改为手动检查。