added !inspire

This commit is contained in:
Sid 2021-12-18 18:36:06 +01:00 committed by GitHub
parent 4feb24898b
commit 924fc26bdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 4 deletions

View file

@ -16,4 +16,7 @@
> Heads or Tails!
>**merry christmas**
> Someone writes "merry christmas" and bot responds w/ legendary vine quote selected from an array
> Someone writes "merry christmas" and bot responds w/ legendary vine quote selected from an array
>**!inspire**
> Bot inspires user with a quote from zenquotes.io

25
main.py
View file

@ -1,19 +1,33 @@
import os
import discord
import requests
import json
import random
client = discord.Client()
my_secret = os.environ['TOKEN']
# arrays containing answers
xmasAnswers = ['Happy Chrismis!', 'Its Chrismin!', 'Merry Chrisis!', 'Merry Chrysler!']
coinflip = ['Heads', 'Not Sonic lol (Tails..)']
# gets a quote from zenquotes.io
def get_quote():
response = requests.get('https://zenquotes.io/api/random')
json_data = json.loads(response.text)
quote = json_data[0]['q'] + ' -' + json_data[0]['a']
return(quote)
# when bot is ready
@client.event # Register an event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
# bot senses a message & responds
@client.event
async def on_message(message):
@ -30,15 +44,15 @@ async def on_message(message):
await message.channel.send(f'Pong :ping_pong: (Bot latency: **{round(client.latency * 1000)}ms**)')
await message.channel.send(file=discord.File('resources/pingpong.gif'))
# user sends "!help", bot sends commands file
# user sends "!help", bot sends commandsfile
elif message.content.lower().startswith("!help"):
await message.channel.send(file=discord.File("commands.md"))
# user sends "!coinflip", bot sends commands file
# user sends "!coinflip", bot returns result
elif message.content.lower().startswith("!coinflip"):
await message.channel.send(random.choice(coinflip))
# user sends "!github", bot sends commands file
# user sends "!github", bot responds w/ my GitHub profile
elif message.content.lower().startswith("!github"):
await message.channel.send('https://github.com/SindreKjelsrud')
@ -46,6 +60,11 @@ async def on_message(message):
elif "merry christmas" in message.content.lower():
await message.channel.send(random.choice(xmasAnswers) + ':santa:')
# user sends "!inspire", bot inspires user
elif message.content.lower().startswith("!inspire"):
quote = get_quote()
await message.channel.send(quote)
# run bot
client.run(my_secret)