discord.py_noob
discord.py_noob

Reputation: 31

How do you extract reddit submission content with praw?

I'm working on a Discord bot right now, where one of its commands brings up a random submission from the r/copypasta subreddit. Right now, my code is as follows:

@client.command(help = 'sends you a link to a copypasta... working on making it an embed')
async def copypasta(ctx):
    reddit = praw.Reddit(client_id = 'XXXX', 
                         client_secret = 'XXXX', 
                         username = 'XXXX', 
                         password = 'XXXX', 
                         user_agent = 'XXXX')
    submission = reddit.subreddit("copypasta").random()
    e = discord.Embed(title=f'{submission.title}', description=f'{submission.url} \n \n requested by {ctx.author.mention}', color=0xFFFFF)

    await ctx.send(embed = e)

I'm looking to change the description to the actual content of the submission: that is, instead of sending the URL, it would actually send the copypasta. I've looked through the documentation, and I've found no method of doing so. How would I extract the submission and place it in my embed?

Upvotes: 2

Views: 405

Answers (1)

Axiumin_
Axiumin_

Reputation: 2145

Use the selftext property of Submission. It'll be empty if the link is just a post.

Your code should look like this:

e = discord.Embed(title=f'{submission.title}', description=f'{submission.selftext} \n \n requested by {ctx.author.mention}', color=0xFFFFF)

Documentation Link: https://praw.readthedocs.io/en/latest/code_overview/models/submission.html?highlight=submission

Upvotes: 2

Related Questions