-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
46 lines (36 loc) · 1.18 KB
/
bot.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
46
import discord
import requests
import os
import json
from dotenv import load_dotenv, find_dotenv
from requests.api import get
from webServer import keep_alive
#my_secret = os.environ['TOKEN']
client = discord.Client()
load_dotenv(find_dotenv())
@client.event
async def on_ready():
print("We have loged in as {0.user}".format(client))
def get_apod():
# When using .env file:
# os.getenv('API_TOKEN')
resp = requests.get(
"https://api.nasa.gov/planetary/apod?api_key=" + os.environ['API_TOKEN'])
content = json.loads(resp.content)
#print(content) # Prints all the JSON
return content["url"],content["title"]
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith("$hello"):
await message.channel.send('Hello!')
elif message.content.startswith("$apod") or message.content.startswith("$APOD"):
url,title=get_apod()
await message.channel.send(title)
await message.channel.send(url)
# Calls the keep_alive function form webServer.py
keep_alive()
# When using .env file:
# os.getenv('BOT_TOKEN')
client.run(os.getenv('BOT_TOKEN')) # os.environ['BOT_TOKEN'])