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")
Advertisement
Answer
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")