当有人试图踢高级管理员或他自己时,我怎样才能让机器人说些啥?
Posted
技术标签:
【中文标题】当有人试图踢高级管理员或他自己时,我怎样才能让机器人说些啥?【英文标题】:How can I make the bot say something when someone tries to kick a higher admin or himself?当有人试图踢高级管理员或他自己时,我怎样才能让机器人说些什么? 【发布时间】:2021-04-27 11:54:34 【问题描述】:当有人试图踢出更高级别的管理员时,机器人什么都不做,甚至没有错误,我希望它改为将文本返回到聊天中。此外,如果有人试图踢/禁止自己,它会起作用,我该如何禁用它?谢谢 这是代码
@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")
【问题讨论】:
这有帮助吗,***.com/questions/48612603/…? 【参考方案1】:你可以比较成员的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")
【讨论】:
以上是关于当有人试图踢高级管理员或他自己时,我怎样才能让机器人说些啥?的主要内容,如果未能解决你的问题,请参考以下文章
Discord.js 禁止/踢命令可供所有用户使用。我怎样才能解决这个问题?
我怎样才能制作一个不和谐的机器人,当他们加入服务器时,他们会 DM 新用户?