TypeError: 'Collection' object is not callableon mongodb

TypeError: 'Collection' object is not callableon mongodb

我一直在尝试使用 mongodb 创建警告系统,但每次用户收到警告时我都很难设置要上传的架构/部分。我得到的错误是下面的内容。我已经查看了所有可能的文档,但我就是不明白。

Traceback (most recent call last):
  File "C:\Users\dargo\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\dargo\PycharmProjects\MaxCodezBot\cogs\warns.py", line 53, in warn
    await self.client.warns.insert(warn)
  File "C:\Users\dargo\PycharmProjects\MaxCodezBot\utils\mongo.py", line 85, in insert
    await self.db.insert_one(dict)
  File "C:\Users\dargo\AppData\Local\Programs\Python\Python39\lib\site-packages\pymongo\collection.py", line 3440, in __call__
    raise TypeError("'Collection' object is not callable. If you "
TypeError: 'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Database' object it is failing because no such method exists.

使用代码

@commands.command()
    @commands.guild_only()
    # @commands.has_guild_permissions(kick_members=True)
    async def warn(self, ctx, user: discord.User, *, reason=None):
        if user is None:
            await ctx.send("You have not provided a user!")
            return

        if user is user.bot:
            await ctx.send(f"<@{ctx.author.id}, you cannot warn a bot!")
            return

        if user.id == ctx.author.id:
            embed = discord.Embed(description=f"<@{ctx.author.id}>, you are not allowed to warn yourself!")

            embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar_url)
            embed.set_footer(text=f"{ctx.message.guild.name} Custom Designed Bot")
            embed.timestamp = ctx.message.created_at

            await ctx.send(embed=embed)
            return

        author_id = ctx.author.id
        guild = ctx.message.guild.id
        first_warning = False
        warn_id = 0
        reason = reason or None

        warn = {
            "_id": ctx.message.guild.id,
            "user": user.id,
            "warn": [{
                "PunishType": 'warn',
                "Moderator": ctx.message.author.id,
                "Reason": reason,
            }],
        }
        await self.client.warns.insert(warn)

我认为代码和错误跟踪不匹配。

错误在 self.db.insert_one(dict)

这意味着您正试图在 db 对象上调用 insert one

应该是db.coll.insert_one(doc)