-
Sujet
-
@bot.tree.command(name="meme") @discord.app_commands.default_permissions(administrator=True) async def meme(i: discord.Interaction): subreddit = "LowQualityMemes" api_url = f"https://www.reddit.com/r/{subreddit}/random/.json" headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3" } response = requests.get(api_url, headers=headers) data = response.json() # Retrieve multiple random memes from the data children = data[0]["data"]["children"] memes = [] for child in children: meme_data = child["data"] if "url" in meme_data and "is_video" in meme_data: if meme_data["is_video"]: if "fallback_url" in meme_data["media"]: memes.append(meme_data) elif not meme_data["is_video"]: memes.append(meme_data) if len(memes) == 10: break if memes: for meme in memes: if meme["is_video"]: video_url = meme["media"]["fallback_url"] await i.response.send_message(video_url) return # Stop processing further memes else: image_url = meme["url"] await i.response.send_message(image_url) else: fallback_video_url = "https://cdn.discordapp.com/attachments/1121806952767442986/1122007978804006953/rapidsave.com_rampant_obsession-o87tn0tdu9ka1.mp4" # Provide a fallback video URL await i.response.send_message(fallback_video_url)
——————–
Lawny – Envoyé depuis le Discord : Culte du code
Vous lisez 5 fils de discussion
Vous lisez 5 fils de discussion
- Vous devez être connecté pour répondre à ce sujet.