Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.5k views
in Technique[技术] by (71.8m points)

python - How can I make the bot say something when someone tries to kick a higher admin or himself?

When someone tries to kick a higher in rank admin the bot does nothing not even an error, I want it instead to return a text into chat. Also if someone tries to kick/ban himself it works, how can I disable that? Thanks here is the code

@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")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you can compare top_role of the members

@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")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...