簡體   English   中英

我想更改我的禁令命令以不禁止任何員工 discord.py

[英]I want to change my ban command to not ban any staff members discord.py

我希望能夠將此代碼更改為員工無論職位如何都不能禁止員工,並且不會像管理員不能禁止 mod 那樣擔任更高的角色。 我試圖將它與員工角色聯系起來,但機器人不發送輸出。

@commands.command()
@commands.has_permissions(ban_members=True)
@commands.bot_has_guild_permissions(ban_members=True)
async def ban(self, ctx, user, *, reason: commands.clean_content = '[No reason given]'):
    """ Ban a user from the current guild. """
    author = ctx.author
    guild = ctx.guild
    user = await self.fetch_user(ctx, user)
    if guild.get_member(user.id) and (guild.get_member(user.id).top_role.position >= guild.me.top_role.position): >This is where heirarchy comes into play
        raise GenericCustomException(
            "Sorry, but I can not ban that user. Maybe try checking my role hierarchy?"
        )
    else:  # this is where I try to pass the mod role to be ignored from banning each other
        if discord.utils.get(user.roles, id=<insert mod role id here>):
            return await ctx.send("you cannot ban a staff member") 
      

我會嘗試搜索用戶是否具有您的某個角色擁有的特定權限,如果為真,則發送消息。 例如,如果我想查看用戶是否具有ban_members權限:

if user.guild_permissions.ban_members:
    return await ctx.send("you cannot ban a staff member")

確保將ban_members替換為適合您需要的任何其他權限。

您可以遍歷用戶的角色並檢查他是否在 mod 角色列表中擁有角色。 我更喜歡使用角色 ID,因為它無法更改。

@commands.command()
@commands.has_permissions(ban_members=True)
@commands.bot_has_guild_permissions(ban_members=True)
async def ban(self, ctx, user, *, reason: commands.clean_content = '[No reason given]'):
    """ Ban a user from the current guild. """
    author = ctx.author
    guild = ctx.guild
    user = await self.fetch_user(ctx, user)
    if guild.get_member(user.id) and (guild.get_member(user.id).top_role.position >= guild.me.top_role.position): >This is where heirarchy comes into play
        raise GenericCustomException(
            "Sorry, but I can not ban that user. Maybe try checking my role hierarchy?"
        )
    else:
        whitelisted_roles = [123456, 456789, 789012] # List of Mod roles 
        for role in user.roles:
            if role.id in whitelisted_roles:
                return await ctx.send("You can't ban this user! He is a moderator!")
        else:
            # ban the user
            pass

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM