Skip to main content
 首页 » 编程设计

python之Discord python 解禁成员

2024年12月31日9jirigala

好的,我的禁止命令有效 ban(member),但是当执行相同操作时,除了使用 unban(member) 输出总是找不到用户. 这是ban命令的代码,unban命令的正确用法是什么?

@commands.command(pass_context = True) 
@commands.has_permissions(ban_members=True) 
async def ban(self, ctx, member:discord.Member=None): 
    """Bans a member.""" 
    if not member: 
        await self.bot.say("Who would you like me to ban, {0.mention}?".format(ctx.message.author)) 
        pass 
    await self.bot.ban(member) 
    await self.bot.say(f"{member.mention} got banned, what a shame...") 
    print(colored('moderation.clf: ', 'blue'), colored('Banned member', 'white')) 

请您参考如下方法:

由于成员代表服务器内的用户,因此您不能为当前被禁止的用户创建成员实例。您必须使用不是特定于服务器的 User 实例来取消禁令,例如 await self.bot.unban(server, user) 其中服务器的类型为 discord.Server 和 discord.User 类型的用户。