Discord.py Guild.bans() 缺少 1 个必需的位置参数: ‘self’

huangapple go评论49阅读模式
英文:

Discord.py Guild.bans() missing 1 required positional argument: 'self'

问题

Code:

@tree.command(name="unban", description="Unbans a member.", guild=discord.Object(id=guildid))
async def unban(ctx, member: str):
        bannedusers = await discord.Guild.bans()
        membername, memberdiscriminator = member.split("#")
        for banentry in bannedusers:
            user = banentry.user
            if (user.name, user.discriminator) == (membername, memberdiscriminator):
                await ctx.guild.unban(user)

Error:
Guild.bans() missing 1 required positional argument: 'self'

I tried also use discord.Guild.unban and discord.Member.unban, both give the same error.

英文:

Code:

@tree.command(name="unban",description="Unbans a member.",guild=discord.Object(id=guildid))
async def unban(ctx,member:str):
        bannedusers = await discord.Guild.bans()
        membername,memberdiscriminator = member.split("#")
        for banentry in bannedusers:
            user = banentry.user
            if (user.name, user.discriminator) == (membername, memberdiscriminator):
                await ctx.guild.unban(user)

Error:
Guild.bans() missing 1 required positional argument: 'self'

I tried also use discord.Guild.unban and discord.Member.unban, both give the same error

答案1

得分: 0

尝试 ctx.guild.bans()

API 参考链接: https://discordpy.readthedocs.io/en/stable/api.html?highlight=guild#discord.Guild.bans

英文:

You're calling discord.Guild which is a class and thus not instantiated. Try ctx.guild.bans()

API Reference: https://discordpy.readthedocs.io/en/stable/api.html?highlight=guild#discord.Guild.bans

huangapple
  • 本文由 发表于 2023年2月9日 03:32:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75390859.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定