首页 > 解决方案 > 命令引发异常:TypeError: unban() 接受 1 个位置参数,但给出了 2 个

问题描述

我在 cog 文件中创建了一个不和谐的机器人取消禁令命令,但是当我去不和谐并尝试取消禁令时,它说

Command raised an exception: TypeError: unban() takes 1 positional argument but 2 were given

这是完整的代码

@commands.command(aliases=['ub'])
@commands.has_permissions(ban_members=True)
async def unban(ctx, *, member):
    banned_users = await ctx.guild.bans()
    member_name, member_discriminator = member.split('#')

    for banned_entry in banned_users:
        user = banned_entry.user

        if (user.name, user.discriminator) == (member_name, member_discriminator):
            
            await ctx.guild.unban(user)
            await ctx.send(f'Unbanned {user.mention}')
            try:
                await member.send("You have been unbanned from Scar Community Server   https://discord.gg/bXGTk9x7 ")
            except:
                await ctx.send("Cannot DM them!")
            return

标签: pythondiscord.py

解决方案


类的任何方法都需要self作为第一个参数。

@commands.command(aliases=['ub'])
@commands.has_permissions(ban_members=True)
async def unban(self, ctx, *, member):
    # ...

推荐阅读