【问题标题】:Link to the meme in Discord.py Meme command链接到 Discord.py Meme 命令中的 meme
【发布时间】:2021-07-05 07:28:20
【问题描述】:

我正在 discord.py 中制作一个机器人,并使用 AIOHTTP 制作了一个 meme 命令。我希望嵌入标题成为 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)
    ```

【问题讨论】:

  • 您可以使用carl-bot(!embedsource) 命令检查嵌入源并复制它。
  • 我自己也做过类似的命令,我建议你使用 Reddit PRAW 包。它会为你做到这一点。我相信,如果我错了,请纠正我,您只需要执行类似于 meme.urlmeme.link 的操作即可获得该 meme 的链接。
  • @Ceres 我没有看到 carl bot 的任何 meme 命令
  • 您可以使用embedsource 命令获取 meme 嵌入的来源。使用源代码,您可以重新设计自己的嵌入,模仿模因

标签: discord discord.py


【解决方案1】:

用这段代码替换它 教程 第 1 步:安装 praw (pip install praw) 第二步:去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)

【讨论】:

    猜你喜欢
    • 2021-08-28
    • 2019-07-30
    • 1970-01-01
    • 2021-07-27
    • 2020-11-24
    • 2021-07-10
    • 1970-01-01
    • 2021-08-17
    • 2022-01-12
    相关资源
    最近更新 更多