【发布时间】:2021-03-29 11:51:57
【问题描述】:
最近我一直在用 python 制作一个不和谐的机器人,我想添加 reddit 命令,正如我在 Dank Memer、MEE6 等机器人上看到的那样,从 reddit 发送图像帖子。我在网上找到了一些代码(我对 discord.py 很陌生),我发现了如何使用 aiohttp 来做到这一点
async def meme(ctx):
embed = discord.Embed(title="Post from r/memes.", description=None, color=0xff0000)
async with aiohttp.ClientSession() as cs:
async with cs.get('https://www.reddit.com/r/memes/new.json?sort=hot') as r:
res = await r.json()
embed.set_image(url=res['data']['children'] [random.randint(0, 25)]['data']['url'])
await ctx.send(embed=embed, content=None)
唯一的问题是我还没有弄清楚如何添加帖子的 url 以便用户可以访问它。
【问题讨论】:
标签: discord discord.py discord.py-rewrite