Reputation: 11
idk what i did wrong for this error code to come but pls help File "/Users/jenniferkarlsson/Desktop/TimmyReWrite/cogs/levelsys.py", line 17, in <module> class levelsys(commands.cog): TypeError: module() takes at most 2 arguments (3 given)
but it would be great if you could help me because this error code is gonna be the end of me it's so annoying Idk what to do because I'm pretty new to discord.py and I cant stand this error code I've been stuck on it for 3hours now here is my code if you need it would be great if you could help me Thanks
import discord
import dns
from discord import file
from discord.ext import commands
from pymongo import MongoClient
level = ["Bronze", "Silver", "Gold"]
levelnum = [5, 10, 15]
cluster = MongoClient(
"mongodb+srv://myusername:<mypassword>@cluster0.47irg.mongodb.net/myFirstDatabase?retryWrites=true&w=majority")
leveling = "discord", "leveling"
class levelsys(commands.cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_ready(ctx):
print("lvl system is up and running")
@commands.Cog.listener()
async def on_message(self, message, ctx=None):
stats = leveling.find_one({"id": message.author.id})
if not message.author.bot:
if stats is None:
newuser = {"id": message.author.id, "xp": 1}
leveling.insert_one(newuser)
else:
xp = stats["xp"] + 5
leveling.update_one({"id": message.author.id}, {"$set": {xp}})
lvl = 0
while True:
if xp < ((50 * (lvl ** 2)) + (50 * (lvl - 1))):
break
lvl += 1
xp -= ((50 * (lvl - 1) ** 2) + (50 * (lvl - 1)))
if xp == 0:
with open('giphy.gif', 'rb') as f:
pictures = discord.File(f)
ss = f"Nice {message.author.mention} you leveled up to level {lvl} <:lvlup:858026926832484352>"
await message.channel.send(ss)
for i in range(len(level)):
if lvl == 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 {level[i]} rank",
color=discord.Colour.light_grey())
embed.set_thumbnail(url=message.author.avatar_url)
await ctx.send(embed=embed)
@commands.command()
async def rank(ctx, self):
stats = leveling.find_one({"id": ctx.author.id})
if stats is None:
embed = discord.Embed(description="You haven't sent any messages, no rank",
color=discord.Colour.light_grey())
await ctx.send(embed=embed)
else:
xp = stats["xp"]
lvl = 0
rankers = 0
while True:
if xp < ((50 * (lvl ** 2)) + (50 * (lvl - 1))):
break
lvl += 1
xp -= ((50 * (lvl - 1) ** 2) + (50 * (lvl - 1)))
boxes = int((xp / (200 ** ((1 / 2) * lvl))) * 20)
rank = leveling.find().sort("xp", - 1)
for x in rank:
rank += 1
if stats["id"] == x["id"]:
break
embed = discord.Embed(title="{}'s level stats".format(ctx.author.name))
embed.add_field(name="Name", value=ctx.author.mention, inline=True)
embed.add_field(name="XP", value=f"{xp}/{int(200 * ((1 / 2) * lvl))}", inline=True)
embed.add_field(name="Rank", value=f"{rank}/{ctx.guild.member_count}", inline=True)
embed.add_field(name="Progress bar [lvl]",
value=boxes * ":blue_square:" + (20 - boxes) * "white_square", inline=False)
embed.set_thumbnail(url=ctx.author.avatar_url)
await ctx.send(embed=embed)
@commands.command()
async def lvlleaderboard(self, ctx, rankings=None):
rankings == leveling.find().sort("xp", - 1)
i = 1
embed = discord.Embed(title="Rankings", color=discord.Colour.light_grey())
for x in rankings:
try:
temp = ctx.guild.get_member(x["id"])
tempxp = x["xp"]
embed.add_field(name=f"{i}: {temp.name}", value=f"Total XP:{tempxp}", inline=False)
i += 1
except:
pass
if i == 11:
break
await ctx.send(embed=embed)
def setup(client):
client.add_cog(levelsys(bot))
Upvotes: 1
Views: 1692
Reputation: 311
ignore my other comment
class levelsys(commands.cog):
should be
class levelsys(commands.Cog):
Subtle difference, but the second has a capital "C" in Cog
Upvotes: 3