-1

我试图制作一个从 giphy 发送 gif 的 Bot。我使用 python 和 Giphy Core Client for Python 完成了它。所以如果有人输入

/OwO Giphy 海绵宝宝

它会发送一个随机的海绵宝宝或其他一些模因。问题是它发送元数据和 gif 5 次。我希望有人可以帮助我机器人只发送 gif 并且只发送 1 次。我有 Python 3.8 版。

        if message.content.startswith("/OwO Giphy") or message.content.startswith("/OwO giphy"):
            try:
                q = message.content
                tag = q.replace('/OwO Giphy ', "")
                api_response = api_instance.gifs_random_get(api_key, tag=tag, rating='pg')
                await message.channel.send(api_response)

            except ApiException as e:
                print("ERROR! Exception from Api try")

图片

4

1 回答 1

0

最终解决方案:我没有添加“embed_url”

if message.content.startswith("/OwO Giphy"): 
api_instance = giphy_client.DefaultApi() 
api_key = 'TOKEN' 
q = message.content tag = q.replace('/OwO Giphy ', "") 
api_response = api_instance.gifs_search_get(api_key, q=tag, rating='pg13') 
gif_list = list(api_response.data) 
giff = random.choice(gif_list) 
await message.channel.send(giff.embed_url)
于 2021-06-08T10:01:44.527 回答