A Java-based Discord bot that provides real-time weather information for any city using the OpenWeatherMap API.
- Get current weather for any city (
!weather <city>) - Get 5-day forecast for any city (
!forecast <city>) - Display of temperature, humidity, wind speed, and weather conditions
- Emoji representation of weather conditions
- Simple command interface
- Error handling for invalid cities or API issues
!weather <city>- Get current weather for a specified city!forecast <city>- Get a 5-day weather forecast for a specified city!hello- Display an introduction and basic command list!help- Show all available commands
Using !weather London:
Weather in London, GB ☁️
Temperature: 15.2°C (Feels like: 14.8°C)
Humidity: 76%
Wind Speed: 4.6 m/s
Condition: Overcast clouds
Using !forecast Tokyo:
5-Day Forecast for Tokyo, JP
Fri, May 20 (12:00) ☀️
Temp: 23.5°C | Humidity: 45% | Clear sky
Sat, May 21 (12:00) ⛅
Temp: 22.1°C | Humidity: 58% | Few clouds
Sun, May 22 (12:00) 🌧️
Temp: 19.8°C | Humidity: 72% | Light rain
...
- Java 17 or higher
- Maven
- Discord Bot Token (with MESSAGE_CONTENT intent enabled)
- OpenWeatherMap API Key (optional, a default key is included)
Copy the .env.example file to .env and add your tokens:
# Discord Bot Configuration
DISCORD_TOKEN=your_discord_token_here
# OpenWeatherMap API Key (optional)
# WEATHER_API_KEY=your_weather_api_key_here
- Go to the Discord Developer Portal
- Create a new application or select your existing one
- Navigate to the "Bot" tab
- Under "Privileged Gateway Intents", enable "MESSAGE CONTENT"
- Save changes
-
Clone the repository
git clone https://github.com/yourusername/discord-weather-bot.git cd discord-weather-bot -
Set up your environment variables (as shown above)
-
Build the project with Maven:
mvn clean package -
Run the bot:
java -jar target/weather-discord-bot-1.0-SNAPSHOT.jarOr simply use:
mvn compile exec:java -Dexec.mainClass="com.example.SimpleWeatherBot"
- Go to the Discord Developer Portal and select your application
- Navigate to OAuth2 → URL Generator
- Select the scopes: "bot"
- Bot Permissions: "Send Messages", "Read Message History"
- Copy and visit the generated URL to add the bot to your server
Contributions are welcome! Please feel free to submit a Pull Request.
MIT