繁体   English   中英

Discord bot kick 命令错误消息 python

[英]Discord bot kick command error message python

所以我找到了这个kick命令的代码,我想知道如何制作它,所以如果发送kick命令的人没有权限,它会回复用户并说他们没有正确的权限。

@commands.has_permissions(administrator=True)
async def kick(ctx, user : discord.Member,*,reason):
  await user.kick(reason=reason)
  await ctx.send(f'{user} kicked for {reason} by {ctx.author}')

那是代码

This should send a message telling users that they don't have permissions if they try to use the command without the proper roles
```python
from discord.ext.commands import MissingPermissions
#Import this at the top of your code

#Write the error handler below the code where you define the kick command
@kick.error
async def kick_error(self, ctx, error):
    if isinstance(error, MissingPermissions):
        await ctx.send(":redTick: You don't have permission to kick members.")
```
For me I would write:
```python
import discord
from discord.ext import commands
from discord.ext.commands import MissingPermissions

client = commands.Bot(command_prefix=("prefix"))

@client.command()
@commands.has_role("Administrator")
async def kick(self, ctx, member : commands.MemberConverter, *, reason=None):
  await member.kick(reason=reason)
  await ctx.send(f"{member} has been kicked, reason: {reason}")

@kick.error
async def kick_error(self, ctx, error):
    if isinstance(error, MissingPermissions):
        await ctx.send(":redTick: You don't have permission to kick members.")
```

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM