0

How can i make a meme command using ASYNCPRAW? i looked in the internet but i didn't find any solution, because there is not much about asyncpraw in general.

elixss
  • 55
  • 5
  • You should have been smarter about it: Post a question and give an answer yourself! ;) – Dominik May 28 '21 at 23:07
  • That's nice. I was looking for this thing for a while now. But here @Dominik is correct. Make that a simple question and "Answer your own question". That would actually make more sense as people usually don't open question with no answers. So they would think that this is just an unanswered questions. – Bhavyadeep Yadav May 29 '21 at 02:26

1 Answers1

0

Here is how to make a meme command in asyncpraw. if you dont want to wait 100 years, look around 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
elixss
  • 55
  • 5