python - 我在 discord.py 中有错误(清除命令)
问题描述
我有这个用于 discord.py 重写的 Python 代码:
@bot.command(pass_context=True)
async def clean(ctx):
if ctx.author.guild_permissions.administrator:
llimit = ctx.message.content[10:].strip()
await ctx.channel.purge(limit=llimit)
await ctx.send('Cleared by <@{.author.id}>'.format(ctx))
await ctx.message.delete()
else:
await ctx.send("You cant do that!")
但每次我得到这个错误:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: '<=' not supported between instances of 'str' and 'int'
这里有人可以帮助我吗?
解决方案
为了声明参数,您可以将单参数可调用对象(如int
)视为转换器。我还将您的权限检查更改为由commands.check
@bot.command(pass_context=True)
@commands.has_permissions(administrator=True)
async def clean(ctx, limit: int):
await ctx.channel.purge(limit=limit)
await ctx.send('Cleared by {}'.format(ctx.author.mention))
await ctx.message.delete()
@clean.error
async def clear_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You cant do that!")
推荐阅读
- twitter-bootstrap - vb-tooltip 的自定义类
- linux-kernel - 如何在 Linux 中分配大的连续内存区域
- reactjs - 子路由不会在 SSR React App 上重新加载
- jquery - 没有从 jQuery 循环中获取值
- javascript - JS 数组中出现最多的元素的问题
- c - 将静态结构添加到作为函数参数的数组
- windows - Windows 1903 中的英特尔 HAXM 安装失败
- python - Python (None) 是 None 但 () 不是 None
- windows - 如何禁用 bcdedit 调试?
- python - 如何在python中打印十六进制而不转换为int?