C
C
cenox2021-02-10 12:03:09
Python
cenox, 2021-02-10 12:03:09

How to send a random GIF through a VK bot?

I'm writing to vkbottle
Hello. How can I send a random gif, from the VK database or through another api?
Let's say the "gif" command is called, after which the bot sends a random gif in the message.
UPD:
I tried to do it through a third-party api, but it gives an error:

vkbottle.utils.exceptions.VKError: (27, 'Group authorization failed: method is unavailable with group auth.', <Method DocsGetUploadServer>, {})

script:
apikey = 'тут ключ'
lmt = 8
search_term = "excited"


@bot.on.chat_message('гиф')
async def gif(message: Message):
  # get the top 8 GIFs for the search term
  r = requests.get(
      "https://g.tenor.com/v1/search?q=%s&key=%s&limit=%s" % (search_term, apikey, lmt))

  if r.status_code == 200:
      # load the GIFs using the urls for the smaller GIF sizes
      top_8gifs = json.loads(r.content)
      dcs = await docs_uploader.upload_doc(top_8gifs)
      await message(attachment=dcs)
  else:
      top_8gifs = None

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex K, 2021-02-10
@alexk111

Judging by the returned error, the VK API method was called docs.getUploadServerwith the group token . Must be called with the user's access key . Source: https://vk.com/dev/docs.getUploadServer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question