I'm making a reddit discord bot and I don't know what I'm doing wrong
import discord
from discord.ext import commands
import praw
reddit = praw.Reddit(client_id = "sda",
client_secret = "fdsf",
username = "aasdsa",
password = "password",
user_agent = "sd")
b = commands.Bot(command_prefix = ".p ")
@b.command()
async def meme(ctx):
subreddit = reddit.subreddit("dankmemes")
all_subs = []
top = subreddit.top(limit = 10)
for sumbission in top:
all_subs.append(sumbission)
random_sub = all_subs.choice()
name = random_sub.title()
url - random_sub.url()
em = discord.Embed(title = name)
em.set_image(url = url)
await ctx.send(embed = em)
It's supposed to send a post from a subreddit whenever I type .p sub, what is wrong and why won't it work? I also tryed this in another .py file and the file won't open without closing immediately. Also, what do I type in user_agent? Here's my application if you need it: https://ibb.co/B64vrWM
import praw
reddit = praw.Reddit(client_id = "example",
client_secret = "example",
username = "Psychological_Win_55",
password = "not_my_real_password",
user_agent = "I don't know what I put here")
subreddit = reddit.subreddit("memes")
all_subs = []
top = subreddit.hot(limit=10)
for sumbission in subreddit.hot(limit=10):
print(sumbission.title)
So I figured it out.
When I was telling python to pick a random submission, I needed to do
import random
and then do
random.choice(all_subs)
and not
random_sub = all_subs.choice()