A discord bot which fetches news from multiple sources. It is build using dicord.py API wrapper for Discord. It uses NewsAPI to fetch the required news headlines.
-
Import the repository on Replit. No need to install dependencies as replit will do it automatically when you execute the bot.
-
Create a new application on Discord Developer Portal and afterwards create a bot on the portal.
-
Generate the invite url for the bot and make sure to give it the following permissions:
- Send Messages
- Send Messages in thread
- Embed Links
-
Add the bot to your server by visiting the generated url and selecting the desired server.
-
Copy the API Token for your bot and place it in the repl.it environment variable as 'TOKEN'.
-
Now, generate the API key for NewsAPI. Add the API key to the repl.it environment vairables as 'NEWSAPIKEY'.
-
Now just execute the main.py file in the repl.
-
As long as it is running, the bot will be online and will respond to commands.
-
Install the dependencies.
-
Clone the repository.
-
Create a new application on Discord Developer Portal and afterwards create a bot on the portal.
-
Generate the invite url for the bot and make sure to give it the following permissions:
- Send Messages
- Send Messages in thread
- Embed Links
-
Add the bot to your server by visiting the generated url and selecting the desired server.
-
Copy the API Token for your bot. Replace the 'TOKEN' on the last line of main.py with the copied token(enclosed in quotes).
-
Now, generate the API key for NewsAPI. Replace 'NEWSAPIKEY' in main.py with this copied key.
-
Now just execute the main.py file:
pyhton main.py
-
As long as it is running, the bot will be online and will respond to commands.
Commands | Description |
---|---|
$top | Displays top 5 headlines in the text channel. |
$q <query> | Searches for news articles with "query". It can be of multiple words. Advanced Search is also supported. - Surround phrases with quotes (") for exact match. - Prepend words or phrases that must appear with a + symbol. - Prepend words that must not appear with a - symbol. - You can use the AND / OR / NOT keywords. |
$tops | Same as $top but it does not send links along with headlines. Useful when you want to reduce clutter due to link preview. |
$qs <query> | Same as $q but it does not send links along with headlines. |
Feel free to improve the code further by optimizing, adding new features, improving readability or any other changes. Any suggestions and feedback will be much appreciated.