【问题标题】:How can I get a random image from image search using a command discord.py如何使用命令 discord.py 从图像搜索中获取随机图像
【发布时间】:2021-07-11 10:37:38
【问题描述】:

我知道我可以发出如下命令:

    async def cat(self, ctx):
      response = requests.get('https://aws.random.cat/meow')
      data = response.json()
      embed = discord.Embed(
          title = 'Kitty Cat ????',
          description = 'Cat',
          colour = discord.Colour.purple()
          )
      embed.set_image(url=data['file'])            
      embed.set_footer(text="")
      await ctx.send(embed=embed)

顺便说一句,不是我的代码 但是我如何像 !image computer 一样发出搜索命令,它会从图像搜索中获取随机的计算机图像并将其发送到频道

【问题讨论】:

  • 欢迎来到 Stack Overflow!人们很少只是简单地为您编写代码。我们希望看到您在代码中付出一些努力并将其显示在问题中。如果您想了解如何操作,请查看here
  • 您要么需要使用google api,例如Google-Images-Search 1.3.8,要么找到类似Unsplash Source的api

标签: python python-3.x discord discord.py bots


【解决方案1】:

您可以按照Bagle 的建议使用Unsplash Source API。

@command(name = "img")
    async def cat(self, ctx, arg):
      embed = discord.Embed(
          title = 'Random Image ?',
          description = 'Random',
          colour = discord.Colour.purple()
          )
      embed.set_image(url='https://source.unsplash.com/1600x900/?{}'.format(arg))            
      embed.set_footer(text="")
      await ctx.send(embed=embed)

并执行命令

{bot_prefix}img computers

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-25
    • 2018-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-23
    • 1970-01-01
    • 2017-05-01
    相关资源
    最近更新 更多