Python Discord bot that scrapes data from FiveThirtyEight's 2024 Election Forecast and updates the bot's nickname with election statistics.
When creating a Discord bot through the Discord Developer Portal, make sure you enable both SERVER MEMBERS INTENT and MESSAGE CONTENT INTENT.
You'll need to install:
beautifulsoup4
requests
discord.py
To invite the bot to a server:
- Select "bot" under scopes.
- Under Bot Permissions, enable:
- View Channels
- Send Messages
- Read Message History
- Change Nickname
You can use an .env file to store environment variables securely (or store them within your IDE if supported). Never share your token with anyone. The .env file should include:
AUTHORIZED_USER_ID=<YOUR_USER_ID>
TOKEN=<DISCORD_BOT_TOKEN>
To update the bots nickname with the latest election statistics, send a Direct Message (DM) to the bot in the following format:
update <server_id_that_the_bot_is_in>
Replace <server_id_that_the_bot_is_in>
with the actual ID of the server where the bot is active.
As of October 27, 2024, this program scrapes data successfully. However, future changes to the website's layout or structure may prevent successful scraping.
Special thanks to FiveThirtyEight for collecting and providing election data. This bot relies on manual calls to scrape data to avoid overloading the website. Please use it responsibly.