1717load_dotenv ()
1818discordtoken = os .getenv ("TOKEN" )
1919openai_api_key = os .getenv ("API_KEY" )
20- openai .api_key = openai_api_key
21-
20+ openai .api_key = openai_api_key
21+ news_key = os . getenv ( "NEWS_API_KEY" )
2222
2323intents = discord .Intents .default ()
2424intents .message_content = True
@@ -35,6 +35,20 @@ async def on_ready():
3535 print ("bot is ready" )
3636
3737
38+ @bot .command ()
39+ async def doc (ctx ):
40+ embed = discord .Embed (title = "List of available commands:" , color = discord .Color .blue ())
41+ embed .add_field (name = "$chat" , value = "This command lets you have a conversation with the bot. Usage: $chat [message]" )
42+ embed .add_field (name = "$meme" , value = "This command sends a random meme. Usage: $meme" )
43+ embed .add_field (name = "$play" , value = "This command plays a YouTube video in the voice channel you are in. Usage: $play [YouTube video URL]" )
44+ embed .add_field (name = "$pause" , value = "This command pauses the currently playing YouTube video. Usage: $pause" )
45+ embed .add_field (name = "$resume" , value = "This command resumes the currently paused YouTube video. Usage: $resume" )
46+ embed .add_field (name = "$stop" , value = "This command stops the currently playing YouTube video. Usage: $stop" )
47+ embed .add_field (name = "$rdog" , value = "This command sends a random dog image. Usage: $rdog" )
48+ embed .add_field (name = "$translate" , value = "This command translates text to a specified language. Usage: $translate [language code] [text]" )
49+ await ctx .send (embed = embed )
50+
51+
3852@bot .command ()
3953async def chat (ctx , * , message : str = None ):
4054 if message is None :
@@ -113,4 +127,18 @@ async def translate(ctx, *, thing):
113127 translation = translator .translate (thing ).text
114128 await ctx .send (translation )
115129
130+ @bot .command ()
131+ async def news (ctx , innews ):
132+ news = requests .get (f"https://newsapi.org/v2/everything?q={ innews } &apiKey={ news_key } " ).json ()
133+ thnews = news ["articles" ]
134+ if news ["status" ] == "ok" :
135+ for i , article in enumerate (thnews ):
136+ if i < 5 :
137+ emend = discord .Embed (title = article ["title" ], description = article ["description" ], url = article ["url" ],color = discord .Color .blue ())
138+ await ctx .send (embed = emend )
139+ else :
140+ break
141+ else :
142+ await ctx .send (f"{ innews } not found please try again" )
143+
116144bot .run (discordtoken )
0 commit comments