我正在使用Pixabay搜索图像,然后我想让我的discord.py机器人说出来。但是,我不知道你需要调用什么功能才能获得图像,这样这个不和谐的机器人就可以将它发送到嵌入式系统中。这是我目前的密码。
@bot.command(name='otter', help='Generates a random otter!')
async def otter(ctx):
r = requests.get('https://pixabay.com/api/?key=keyisherebutforprivacyreasonsiamremovingitlol&q=otter&image_type=photo')
r = r.json()
for item in r['hits']:
print(item['type'])
embed = discord.Embed(title='Otter test', color=discord.Color.from_rgb(226, 22, 31))
embed.set_image(url=item[random.choice(range(0, 5))]) # The problem is here, as I took the image bit away and the embed sent fine.
embed.set_footer(text='Powered by pixabay.')
await ctx.send(embed=embed)基本上,它只是打印出来:照片一遍又一遍,这是很好的,因为这意味着搜索工作。作为测试,我删除了set映像部分,嵌入也很好,所以我知道这是embed.set_image的一个问题。如果有人知道真正得到并发送图像的正确方法,我会非常感激的。谢谢!我在控制台中也没有收到错误消息。
发布于 2020-05-13 01:19:35
https://stackoverflow.com/questions/61764464
复制相似问题