discord - 链接到 Discord.py Meme 命令中的 meme
问题描述
我正在 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)
```
解决方案
用此代码替换它 教程第 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)
推荐阅读
- c# - C# Double 不会从算术中给出正确的结果
- python - 使用 gstreamer 将 OpenCV 流式传输到 RTSP 时 FPS 较低
- r - R markdown 不显示绘图,只显示绘图路径
- python - 如何解决 Dash ploty 中的此重复回调输出错误
- python - 导入pyinputplus模块的问题
- node.js - 有没有办法清除旧的应用程序缓存(Nextjs 应用程序)
- gmail-api - Creating a Email Signature using GMAIL API
- java - 每当活动被杀死或导航到新活动时,图像就会消失
- jquery - 如何使用jQuery更改带有冒号和波浪号的css类的边框和背景颜色?
- javascript - 多个 Array.prototype.map() 方法时未捕获的(承诺中)错误