python - 即使标签存在,它说什么也没找到
问题描述
我正在尝试创建一个从 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])
解决方案
推荐阅读
- regex - 用于匹配组后跟特定字符的正则表达式
- html - 语义 UI 网格列不适应高度
- webpack - StyleLint - 忽略特定的文件夹和文件
- sql-server - 如何在 SQL SERVER 中通过存储过程插入数据表
- qt - Qlist 如何处理指针
- spring - 使用 Spring Boot 在运行时启用和禁用端点
- c# - DontDestroyOnLoad 通过音频场景
- python - 将 2checkout 与 Django 2.2 集成
- javascript - 尝试使用 Vue 客户端从我的数据库中删除列时出错
- java - 我最近创建了这个项目,它的显示无法解决 R ,如何解决这个问题