【问题标题】:Discord.py Ban Command IssuesDiscord.py 禁止命令问题
【发布时间】:2020-05-26 09:53:33
【问题描述】:

我的禁止命令有问题,我的管理员可以互相禁止,我不希望这样,但我不知道如何在我的代码中修复它

#Ban command
@client.command()
@commands.has_permissions(ban_members=True)
async def ban(ctx, member : discord.Member, *, reason=None):
    await member.ban(reason=reason)
    await ctx.send(f'{user.mention} has been banned!')

我希望它变成这样,但我对 python 很陌生,我不知道如何编写它(注释部分)

#Ban command
@client.command()
@commands.has_permissions(ban_members=True)
async def ban(ctx, member : discord.Member, *, reason=None):
  #if mentioned user has the same role as the author: 
    await ctx.send('Cant ban Moderators/Admins')
  else:
    await member.ban(reason=reason)
    await ctx.send(f'{user.mention} has been banned!')

【问题讨论】:

    标签: python python-3.x discord discord.py discord.py-rewrite


    【解决方案1】:
    #Ban command
    @client.command()
    @commands.has_permissions(ban_members=True)
    async def ban(ctx, member : discord.Member, *, reason=None):
        check = False
        for i in member.roles:
            if i in ctx.author.roles[1:]:
                check = True
    
        if(check):
            await ctx.send('Cant ban Moderators/Admins')
        else:
            await member.ban(reason=reason)
            await ctx.send(f'{user.mention} has been banned!')
    

    【讨论】:

    • 我将如何让这个全球化?就像我的机器人在许多不同的服务器中一样。我希望如果这个人具有相同的角色,他们不能互相禁止,也不能禁止任何具有更高角色的人。但我希望角色较高的人能够禁止较低的角色。
    • @ParrotSec03 据我所知,Discord 角色没有层次结构,因为它们不是默认的,而是由服务器所有者创建的。我更新了我的帖子,以便如果版主试图禁止具有版主角色的人,它会失败。但是,如果他们共享任何角色,这确实会导致失败。这是我能找到的最好的,我对这个库的了解有限,所以也许其他人有更好的解决方案。
    • 好的,感谢您的帮助,这将一直有效,直到我了解有关 python 的更多信息。谢谢!
    猜你喜欢
    • 2018-11-07
    • 2019-08-31
    • 1970-01-01
    • 2020-06-16
    • 2021-04-06
    • 2021-05-11
    • 1970-01-01
    • 2021-07-27
    • 2020-07-09
    相关资源
    最近更新 更多