前提
discord.pyでF-BOXというBOTを作っています。
そのBOTにランダムにGIFを送信させるコマンドを作りたいです。
実現したいこと
- BOTにランダムにGIFを送信させるコマンドを作りたい
コード
py
1追記:途中のソースコード 2apikey = "伏せます" 3ckey F-BOX GIFGIF" 4lmt = 1 5r = requests.get("https://tenor.googleapis.com/v2/featured?key=%s&client_key=%s&limit=%s" % (apikey, ckey, lmt)) 6r = requests.get("https://tenor.googleapis.com/v2/categories?key=%s&client_key=%s" % (apikey, ckey)) 7if r.status_code == 200: 8featured_gifs = json.loads(r.content) 9else: 10featured_gifs = None 11 12 13 14if r.status_code == 200: 15categories = json.loads(r.content) 16else: 17categories = None 18gif = random.choice(data["results"])
tenor apiはv2です。
https://teratail.com/questions/o92dxpsm0i1yi1 の重複質問だと思われます。
非同期関数ではaiohttpを使いましょう。公式でも言われてます。
https://discordpy.readthedocs.io/ja/latest/faq.html#what-does-blocking-mean