My code:
JavaScript
x
28
28
1
@commands.Cog.listener()
2
async def on_message(self, message, xp=None):
3
if message.channel.id in talk_channels:
4
stats = levelling.find_one({"id": message.author.id})
5
if not message.author.bot:
6
if stats is None:
7
newuser = {"id": message.author.id, xp: 100}
8
levelling.insert_one(newuser)
9
else:
10
xp = stats["xp"] + 5
11
levelling.update_one({"id": message.author.id}, {"$set": {"xp": xp}})
12
lvl = 0
13
while True:
14
if xp < ((50 * (lvl ** 2)) + (50 * lvl)):
15
break
16
lvl += 1
17
xp -= ((50 * (lvl ** 2)) + (50 * lvl))
18
if xp == 0:
19
await message.message.send(
20
f"Well done {message.author.mention}! You leveled up to **level: {lvl}**!")
21
for i in range(len(level)):
22
if level == levelnum[i]:
23
await message.author.add_roles(
24
discord.utils.get(message.author.guild.roles, name=level[i]))
25
embed = discord.Embed(description=f"{message.author.mention}You have gotten the role **{level[i]}**!!!")
26
embed.set_thumbnail(url=message.author.avatar_url)
27
await message.channel.send(embed=embed)
28
Connection to the db code:
JavaScript
1
4
1
client = MongoClient("urlhere")
2
db = client.Discord
3
levelling = client["Discord"], ["leveling"]
4
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:
JavaScript
1
3
1
db = client.Discord
2
levelling = db.leveling
3