Answer the question
In order to leave comments, you need to log in
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>, {})
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question