我用python-pixabay尝试搜索水獭图片,然后让我的discord.py机器人以嵌入的方式发送图片。当我搜索图片并得到图片后,我将其打印出来,但它没有打印任何东西,所以我非常确定是图片搜索的问题。我没有得到任何错误信息,但就是不能工作。
这是我的代码。
import pixabay
import discord
pixa = os.getenv('PIXABAY_KEY')
image = Image(pixa)
@bot.command(name='otter', help='Generates a random otter!')
async def otter(ctx):
page = random.choice(range(0, 4))
embed = discord.Embed(title='Otter', color=discord.Color.from_rgb)
embed.set_image(url=ims)
embed.set_footer(text='Powered by pixabay.')
await ctx.send(embed=embed)
bot.run(TOKEN)
我没有展示所有的代码 因为里面有一些敏感的东西 但我展示了所有你需要看到的东西。Pixabay肯定已经安装好了,因为我是通过 PyPi网站
我注意到一件事,就是描述是空的。通常情况下,如果嵌入的字段是空的,就不会发送,所以我建议你至少检查一下,在嵌入中加入一个 \u200b
(空字符)*或某种描述的文本。
此外, color
参数似乎没有实际的值。discord.Color.from_rgb()
实际上是一个在0-255之间取3个整数值的方法(#FFFFFF,#000000不允许)。
顺便说一下,你可以使用 这个 网站获取颜色的十六进制代码。
embed = discord.Embed(title="Otter", description="Some text!", color=discord.Color.from_rgb(85, 177, 74))
# equivalent
embed = discord.Embed(title="Otter", description="Some text!", color=0x55b14a)
*description="\u200b"