Correctif

This commit is contained in:
Valentin Moguérou 2023-12-18 00:43:18 +01:00
parent 6a2b2cb1ea
commit 65ec845770
1 changed files with 7 additions and 5 deletions

View File

@ -3,6 +3,7 @@ import random
import aiohttp import aiohttp
import asyncio import asyncio
from os import getenv
from dotenv import load_dotenv from dotenv import load_dotenv
from discord import app_commands from discord import app_commands
from discord import Embed from discord import Embed
@ -18,7 +19,7 @@ class Fact(MyCog):
self.bot = bot self.bot = bot
@app_commands.command(name="fact") @app_commands.command(name="fact")
async def fact(self, interaction: discord.Interaction, private=False): async def fact(self, interaction: discord.Interaction, private: bool=False):
""" """
Vous reprendriez bien un petit shot de culture G ? Vous reprendriez bien un petit shot de culture G ?
:param interaction: discord interaction :param interaction: discord interaction
@ -33,14 +34,15 @@ class Fact(MyCog):
try: try:
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
response = await session.get("https://fr.wikipedia.org/api/rest_v1/page/random/summary", headers=headers) response = await session.get("https://fr.wikipedia.org/api/rest_v1/page/random/summary", headers=headers)
data = await response.json()
embed = Embed( embed = Embed(
title=response.json.get("title", "Titre inconnu"), title=data.get("title", "Titre inconnu"),
url=response.json.get("content_urls").get("desktop").get("page"), url=data.get("content_urls").get("desktop").get("page"),
description=response.json.get('extract') description=data.get('extract')
) )
embed.set_thumbnail(response.json.get('thumbnail').get('source')) embed.set_thumbnail(url=data.get('thumbnail').get('source'))
await interaction.response.send_message("", embed=embed, ephemeral=private) await interaction.response.send_message("", embed=embed, ephemeral=private)
except Exception as e: except Exception as e: