当有人试图踢更高的管理员或他自己时,我如何让机器人说些什么?

时间:2021-01-23 01:39:30

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

当有人试图踢更高的管理员级别时,机器人什么也不做,甚至是错误,我希望它改为将文本返回到聊天中。此外,如果有人试图踢/禁止自己它有效,我该如何禁用它?谢谢 这是代码

@client.command()
@commands.has_permissions(kick_members = True)
async def kick(ctx, member : discord.Member, *, reason=None):
  await member.kick(reason=reason)
  await ctx.channel.send(f"User {member} got kicked")

 @client.command()
 @commands.has_permissions(ban_members = True)
 async def ban(ctx, member : discord.Member, *, reason=None):
    await member.ban(reason=reason)
    await ctx.channel.send(f"User {member} got banned")

1 个答案:

答案 0 :(得分:0)

可以比较成员的top_role

@client.command()
@commands.has_permissions(kick_members = True)
async def kick(ctx, member : discord.Member, *, reason=None):
    if ctx.author.top_role <= member.top_role:
        await ctx.send("The person you tried to kick has equal or higher role than you")
        return
    await member.kick(reason=reason)
    await ctx.channel.send(f"User {member} got kicked")

@client.command()
@commands.has_permissions(ban_members = True)
async def ban(ctx, member : discord.Member, *, reason=None):
    if ctx.author.top_role <= member.top_role:
        await ctx.send("The person you tried to ban has equal or higher role than you")
        return
    await member.ban(reason=reason)
    await ctx.channel.send(f"User {member} got banned")