Skip to content
Advertisement

my leveling bot(discord) seems to gives a error Command raised an exception: AttributeError: ‘tuple’ object has no attribute ‘find_one’

My code:

@commands.Cog.listener()
    async def on_message(self, message, xp=None):
        if message.channel.id in talk_channels:
            stats = levelling.find_one({"id": message.author.id})
            if not message.author.bot:
                if stats is None:
                    newuser = {"id": message.author.id, xp: 100}
                    levelling.insert_one(newuser)
                else:
                    xp = stats["xp"] + 5
                    levelling.update_one({"id": message.author.id}, {"$set": {"xp": xp}})
                    lvl = 0
                    while True:
                        if xp < ((50 * (lvl ** 2)) + (50 * lvl)):
                            break
                        lvl += 1
                    xp -= ((50 * (lvl ** 2)) + (50 * lvl))
                    if xp == 0:
                        await message.message.send(
                            f"Well done {message.author.mention}! You leveled up to **level: {lvl}**!")
                        for i in range(len(level)):
                            if level == levelnum[i]:
                                await message.author.add_roles(
                                    discord.utils.get(message.author.guild.roles, name=level[i]))
                                embed = discord.Embed(description=f"{message.author.mention}You have gotten the role **{level[i]}**!!!")
                                embed.set_thumbnail(url=message.author.avatar_url)
                                await message.channel.send(embed=embed)

Connection to the db code:

client = MongoClient("urlhere")
db = client.Discord
levelling = client["Discord"], ["leveling"]

Error: Command raised an exception: AttributeError: 'tuple' object has no attribute 'find_one'

Advertisement

Answer

You should change the connection to the db code to:

db = client.Discord
levelling = db.leveling
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement