Skip to content

Astronomy-Discord-Bot is an open-source Discord Bot that automatically sends "Astronomy Picture Of The Day" and posts it in a channel on your server. Each day a different image or photograph of our universe is featured, along with a brief explanation written by a professional astronomer. Astronomy Picture of the Day is provided by NASA and Michi…

Notifications You must be signed in to change notification settings

0xtaufeeq/Astronomy-Discord-Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Astronomy-Discord-Bot

Code

from os import name
import discord
import aiohttp
import requests
from discord_components import*
from discord import flags
from discord.ext import commands, tasks

client = commands.Bot(command_prefix=commands.when_mentioned_or('.'))
client.remove_command('help')

aopdkey = "AOPDKEY"

@client.command()
async def apod(ctx):
    client.ses = aiohttp.ClientSession()
    url = f'https://api.nasa.gov/planetary/apod?api_key={aopdkey}'
    async with client.ses.get(url) as r:
        if r.status in range(200, 299):
            data = await r.json()
            url = data['url']
            imgtitle = data['title']
            imgdate = data['date']
            explanation = data['explanation']
            ogimg = data['hdurl']
            credit = data['copyright']
            embed = discord.Embed(
                title='🌠 Astronomy Picture Of The Day',
                description=f'**Date -** {imgdate}', color = 000000, timestamp=ctx.message.created_at).set_image(
                url=url).add_field(name=imgtitle, 
                value=f'**Explaination - **\n{explanation}').add_field(name='Original Image -',
                value=f'[Click Here]({ogimg})',inline=False).add_field(name='Image Credit & Copyright -',
                value=credit).set_footer(text="Requested by: {}".format(ctx.author.display_name))
            await ctx.send(embed=embed, 
                        components=[
                            Button(style=ButtonStyle.URL, label='View in browser', url='https://apod.nasa.gov/apod/astropix.html')
                            ],
                            
                        )
           
@client.event
async def on_ready():
    DiscordComponents(client)
    
    print(f'{client.user} has connected to Discord!')

client.run('BOT-TOKEN')```

About

Astronomy-Discord-Bot is an open-source Discord Bot that automatically sends "Astronomy Picture Of The Day" and posts it in a channel on your server. Each day a different image or photograph of our universe is featured, along with a brief explanation written by a professional astronomer. Astronomy Picture of the Day is provided by NASA and Michi…

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages