![](/img/trans.png)
[英]How to make my discord.py rewrite bot send a Private Message to the message author
[英]discord.py how to make the bot not to kick the message author
我有一个踢命令
@commands.has_permissions(kick_members=True)
async def kick(self, ctx, member : discord.Member, *, reason=None):
await member.kick(reason=reason)
await ctx.trigger_typing()
embed = discord.Embed(title=f"{gem} **User kicked!**", color=colgreen)
embed.add_field(name="**{} has been succesfully kicked from the server!**".format(member), value="**Reason: {}.**".format(reason), inline=False)
embed.set_footer(text="{0}\nID: {1}\n{2}".format(ctx.message.author.name, ctx.message.author.id, datetime.datetime.now().strftime("%A, %B %d %Y at %H:%M:%S %p")), icon_url=ctx.message.author.avatar_url)
await ctx.send(embed=embed)
但是如果一个拥有踢成员权限的用户试图踢自己,机器人就会踢他们。
我怎样才能让机器人忽略用户并发送一个你不能踢自己的错误?
我尝试了 if 和 else 语句,但它不起作用......我会得到一个错误,或者什么都没有......
您可以添加 if 语句来检查用户是否等于作者,例如:
@commands.command()
@commands.has_permissions(kick_members=True)
async def kick(self, ctx, member : discord.Member, *, reason=None):
if member == ctx.author: # Check if the user is the same as the author
return
await member.kick(reason=reason)
await ctx.trigger_typing()
embed = discord.Embed(title=f"{gem} **User kicked!**", color=colgreen)
embed.add_field(name="**{} has been succesfully kicked from the server!**".format(member), value="**Reason: {}.**".format(reason), inline=False)
embed.set_footer(text="{0}\nID: {1}\n{2}".format(ctx.message.author.name, ctx.message.author.id, datetime.datetime.now().strftime("%A, %B %d %Y at %H:%M:%S %p")), icon_url=ctx.message.author.avatar_url)
await ctx.send(embed=embed)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.