我知道我做错了什么,但请帮助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)
,但如果你能帮助我,那就太好了,因为这个错误代码将是我的末日,太烦人了,我该怎么办,因为我是discord.py的新手,我受不了这个错误代码,我已经被困在上面3个小时了,如果你需要我的代码,那就太好了,如果你能帮助我,谢谢
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))
发布于 2021-07-05 02:50:26
忽略我的其他评论
类级别(commands.cog):
应该是
类级别(commands.Cog):
细微的差别,但第二个在Cog中有一个大写的"C“
https://stackoverflow.com/questions/68136566
复制相似问题