【问题标题】:How to make a meme command using asyncpraw in discord.py?如何在 discord.py 中使用 asyncpraw 制作 meme 命令?
【发布时间】:2021-08-17 03:19:45
【问题描述】:

如何使用 ASYNCPRAW 制作 meme 命令?我查看了互联网,但没有找到任何解决方案,因为一般来说 asyncpraw 并没有太多。

【问题讨论】:

  • 你应该更聪明一点:发布问题并自己给出答案! ;)
  • 很好。我一直在寻找这个东西。但是这里@Dominik 是正确的。把它变成一个简单的问题并“回答你自己的问题”。这实际上更有意义,因为人们通常不会在没有答案的情况下提出问题。所以他们会认为这只是一个没有答案的问题。

标签: python discord discord.py praw asyncpraw


【解决方案1】:

这是在 asyncpraw 中创建 meme 命令的方法。如果你不想等待 100 年,请环顾 here

    import discord
    from discord import Embed
    from discord.ext import commands
    import asyncpraw
    import random
    
    @commands.command(name="meme")
    async def meme(self, ctx, subred="memes"): # default subreddit is memes, later in the command you can select one of your choice (example: !meme python --> chooses r/python reddit post)
        msg = await ctx.send('Loading ... ')

        reddit = asyncpraw.Reddit(client_id='clientid',
                                  client_secret='clientsecret',
                                  username='username',
                                  password='password',
                                  user_agent='useragent')

        subreddit = await reddit.subreddit(subred)
        all_subs = []
        top = subreddit.top(limit=250) # bot will choose between the top 250 memes

        async for submission in top:
            all_subs.append(submission)

        random_sub = random.choice(all_subs)

        name = random_sub.title
        url = random_sub.url

        embed = Embed(title=f'__{name}__', colour=discord.Colour.random(), timestamp=ctx.message.created_at, url=url)

        embed.set_image(url=url)
        embed.set_author(name=ctx.message.author, icon_url=ctx.author.avatar_url)
        embed.set_footer(text='Here is your meme!')
        await ctx.send(embed=embed)
        await msg.edit(content=f'<https://reddit.com/r/{subreddit}/> :white_check_mark:') # < and > remove the embed link
        return

【讨论】:

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