我有以下Python代码用于discord.py重写:
@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'
这里有人可以帮我吗?
答案 0 :(得分:0)
limit
函数的purge
参数采用整数作为值
尝试做这样的事情
@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=int(llimit))
await ctx.send('Cleared by <@{.author.id}>'.format(ctx))
await ctx.message.delete()
else:
await ctx.send("You cant do that!")
我不太确定您要使用content[10:].strip()
完成什么工作,但是如果您想忽略命令的!clean
部分,则使用的数字太大。 content[7:]
就足够了
答案 1 :(得分:0)
您可以将单个参数可调用对象(例如a.active { background: #ccc;}
a.active ~ * { background: yellow }
a { background: red }
)像converters一样用于声明参数。我也将您的权限检查更改为由commands.check
int