-
Notifications
You must be signed in to change notification settings - Fork 0
/
memebot.py
45 lines (34 loc) · 1.3 KB
/
memebot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import discord
import praw
import random
import os
reddit = praw.Reddit(
client_id='personal use script', # personal use script
client_secret='secret key', # secret key
user_agent='python:meme_bot:v1.0 (by /u/USERNAME_HERE)' # CHANGE THE NAME TO YOURS
)
subreddits = ['memes', 'Memes_Of_The_Dank'] # you can here change what subreddits the bot will use
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('!meme'):
subreddit_name = random.choice(subreddits)
subreddit = reddit.subreddit(subreddit_name)
posts = list(subreddit.hot(limit=50))
post = random.choice(posts)
title = post.title
url = post.url
if url.endswith(('.jpg', '.jpeg', '.png')):
embed = discord.Embed(title=title, url=url)
embed.set_image(url=url)
await message.channel.send(embed=embed)
else:
await message.channel.send(f'{title}\n{url}')
client.run('TOKEN') # replace TOKEN with your bot token