首页 > 解决方案 > 即使标签存在,它说什么也没找到

问题描述

我正在尝试创建一个从 furry.booru API 中提取的命令,但标签(确实存在)只是说“没有找到”。

我对 discord.py 的这个 API 有一些新的东西,所以请帮忙。

我试过的代码如下。

@bot.command(aliases=['fb'])
async def furrybooru(ctx, *, tags: str):
      await ctx.message.delete()
      """Searches furry.booru for images of hentai"""
      await ctx.channel.trigger_typing()
      tags = strip_global_mentions(tags, ctx)
      try:
           data = requests.get(
            "https://furry.booru.org/index.php?page=dapi&s=post&q=index&json=1&limit={}&tags={}"
            .format(limit, tags),
            headers=header).json() #index.php?page=dapi&s=post&q=index&deleted=show
      except json.JSONDecodeError:
          await ctx.send("Couldn't find anything :(")
          return

      count = len(data)
      if count == 0:
          await ctx.send("Couldn't find anything :(")
          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("https://furry.booru.org//samples/{}/sample_{}?{}".format(
              image["directory"], image["image"], image["id"]))
    #await ctx.send("nsfw.results", ctx).format(image_count, count, tags, "\n".join(images))
      await ctx.send(images[0])

标签: pythondiscorddiscord.py

解决方案


推荐阅读