【发布时间】:2021-10-24 21:23:20
【问题描述】:
我制作了一个不和谐的机器人,当你输入某个命令时它会显示 gif,但问题是它在前半部分运行良好,但在不使用时需要很长时间才能显示 gif。 基本上它在不使用时不会立即显示 gif。 这是我写的代码:
@client.command()
async def gif(ctx, *, q = 'dance'):
api_key = 'Some Key here'
api_instanc = giphy_client.DefaultApi()
try:
api_responce = api_instanc.gifs_search_get(api_key, q, limit = 7,rating = 'r')
lst = list(api_responce.data)
giff = random.choice(lst)
emb = discord.Embed(title = f"Requested by {ctx.author} " + q )
emb.set_image(url= f'https://media.giphy.com/media/{giff.id}/giphy.gif')
await ctx.channel.send(embed = emb)
except ApiException as e:
await ctx.channel.send("API EXCEPTION")
它没有显示任何错误,但长时间后不起作用。 任何用 aiohttp 重写的代码都将不胜感激,因为我正在学习这一点。
【问题讨论】:
标签: discord.py