我正在 discord.py 中制作一个机器人,并使用 AIOHTTP 制作了一个 meme 命令。我希望嵌入标题是模因的链接,而页脚应显示赞成票以及屏幕截图中的所有内容。
这是代码
@client.command(aliases=['memes'])
async def meme(ctx):
embed = discord.Embed(title='Meme', description=None)
async with aiohttp.ClientSession() as cs:
async with cs.get('https://www.reddit.com/r/wholesomememes/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)
```
答案 0 :(得分:0)
用这个代码替换它 教程 第 1 步:安装 praw(pip install praw) 第 2 步:转到 https://www.reddit.com/prefs/apps 创建应用 第 3 步:复制 client_id 和 client_secret 第 4 步:运行机器人
@bot.command()
async def meme(ctx):
reddit = praw.Reddit(client_id='clientidhere',
client_secret='clientsecret',
user_agent='python')
memes = reddit.subreddit("memes").random()
await ctx.send(memes.url)