added !plsdog command

This commit is contained in:
Sid 2021-12-18 23:11:02 +01:00 committed by GitHub
parent 67e24d0544
commit c2884e75cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View file

@ -23,3 +23,6 @@
>**!plsmeme**
> Bot supplies with premium memes from subreddits across Reddit from Huge RedditMemesAPI
>**!plsdog**
> Bot supplies with pictures of cute doggos across the whole internet through Dog API

22
main.py
View file

@ -12,8 +12,10 @@ my_secret = os.environ['TOKEN']
# arrays containing answers
xmasAnswers = ['Happy Chrismis!', 'Its Chrismin!', 'Merry Chrisis!', 'Merry Chrysler!']
coinflip = ['Heads', 'Not Sonic lol (Tails..)']
dogTitles = ['Who let the dogs out?', 'woof', 'Whos a good boy!', 'meow', 'Mr. GoodBoy']
## APIs
# gets a quote from zenquotes.io
def get_quote():
response = requests.get('https://zenquotes.io/api/random')
@ -23,8 +25,8 @@ def get_quote():
# gets a meme from Huge RedditMemesAPI
def get_meme():
r = requests.get('https://memes.blademaker.tv/api?lang=en')
res = r.json()
response = requests.get('https://memes.blademaker.tv/api?lang=en')
res = response.json()
title = res['title']
ups = res['ups']
downs = res['downs']
@ -34,12 +36,21 @@ def get_meme():
meme.set_footer(text=f"👍:{ups}")
return meme
# gets a dog from Dog API
def get_dog():
response = requests.get('https://dog.ceo/api/breeds/image/random')
res = response.json()
dog = discord.Embed(title = random.choice(dogTitles))
dog.set_image(url = res['message'])
return dog
# when bot is ready
@client.event # Register an event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
## MESSAGE RESPONSES
# bot senses a message & responds
@client.event
async def on_message(message):
@ -82,6 +93,11 @@ async def on_message(message):
meme = get_meme()
await message.channel.send(embed = meme)
# user sends "!plsdog", bot sends picture of dog from Dog API
elif message.content.lower().startswith("!plsdog"):
dog = get_dog()
await message.channel.send(embed = dog)
# run bot
client.run(my_secret)
client.run(my_secret)