【问题标题】:How to fix discord.py MongoDB not updating如何修复 discord.py MongoDB 不更新
【发布时间】:2020-11-11 19:31:48
【问题描述】:

我的代码: 如果 userexp > userlevel_threshold: print("升级!") await self.bot.exp.update_by_id({"_id": message.author.id, "level": userlevel + 1, "exp": userexp + 1})

它会打印“升级!”但它不会更新数据库中的任何内容。没有错误。

【问题讨论】:

    标签: python-3.x database mongodb discord.py discord.py-rewrite


    【解决方案1】:
    if userexp > userlevel_threshold:
        print('level up')
        updated_level = {
            "level": userlevel+1, 
            "exp": userexp+1
            }
        self.bot.exp.update_one({'_id':f'{message.author.id}'},{'$set':updated_level})
    

    您可以使用[update_one]函数通过此代码更新指定用户的级别!
    [other examples]

    【讨论】:

      猜你喜欢
      • 2019-12-05
      • 1970-01-01
      • 2020-09-17
      • 2011-06-19
      • 1970-01-01
      • 2016-11-16
      • 1970-01-01
      • 2021-09-13
      • 2021-06-10
      相关资源
      最近更新 更多