命令引发异常:TypeError:send()接受1到2个位置参数,但给出了3个

2024-09-28 22:40:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我不断收到命令引发异常:TypeError:send()接受1到2个位置参数,但给出了3个

我如何修理dis

limit = 500
@bot.command()
async def rule34(ctx, *, tags:str):
        """Searches rule34.xxx for the specified tagged images"""
        await ctx.channel.trigger_typing()
        tags = strip_global_mentions(tags, ctx)
        try:
            data = requests.get("http://rule34.xxx/index.php?page=dapi&s=post&q=index&json=1&limit={}&tags={}".format(limit, tags), headers=header).json()
        except json.JSONDecodeError:
            await ctx.send("nothing found chief")
            return

        count = len(data)
        if count == 0:
            await ctx.send("nothing found cheif")
            return
        image_count = 4
        if count < 4:
            image_count = count
        images = []
        for i in range(image_count):
            image = data[random.randint(0, count)]
            images.append("http://img.rule34.xxx/images/{}/{}".format(image["directory"], image["image"]))
        await ctx.send("nsfw.results", ctx).format(image_count, count, tags, "\n".join(images))

Tags: imagesendjsonformathttpfordatacount
1条回答
网友
1楼 · 发布于 2024-09-28 22:40:34

据我所知,您只是试图发送一条格式良好的消息,其中包含所有变量,因此这方面的一个示例解决方案可能是:

await ctx.send("nsfw.results: {0}/{1}\nTags: {2}\n{3}".format(image_count, count, tags, "\n".join(images)))

与原来的最后一行相比已修复的问题:

  • 已删除传递给send函数的ctx参数
  • 将.format放在字符串上,而不是.send函数
  • nsfw.results字符串更改为可以格式化的字符串

有用链接: Python string.format() documentationDedicated Pyformat site

相关问题 更多 >