Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- import os
- import requests
- import json
- client = discord.Client()
- def GetWeather(city):
- url = 'http://api.openweathermap.org/data/2.5/weather?q={}&appid=YourApiKey&units=metric'.format(city)
- res = requests.get(url)
- data = res.json()
- temp = data ["main"] ["temp"]
- humid = data ["main"] ["humidity"]
- wind = data ["wind"] ["speed"]
- desc = data ["weather"] [0] ["description"]
- weather = "\n\
- Description: " + desc +"\nTemp: {}°C".format(temp)+ "\nWind speed: {}m/s".format(wind)+ "\nHumidity: {}%".format(humid)
- return weather
- @client.event
- async def on_ready():
- print('Logged in as {}'.format(client))
- @client.event
- async def on_message(message):
- if message.author == client.user:
- return
- if message.content.startswith('$weather'):
- wordlist = message.content.split()
- city = wordlist[1:]
- await message.channel.send(GetWeather("".join(city)))
- client.run(your_token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement