Skip to content

Commit 6970ca5

Browse files
author
forceCpp
committed
new command added now you can see the news from discord and better documentation added
1 parent 30126e3 commit 6970ca5

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

main.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
load_dotenv()
1818
discordtoken = os.getenv("TOKEN")
1919
openai_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

2323
intents = discord.Intents.default()
2424
intents.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()
3953
async 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+
116144
bot.run(discordtoken)

0 commit comments

Comments
 (0)