Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 81 lines (74 sloc) 3.6 KB
import discord
import weather
import help #these are the 2 other files I made
#an array of all the cities in the uk
#got this from https://gist.github.com/LetsDoughNut/fb1ea8c147e6af4c12df28bd33785e3f
cities = ['Avon', 'Bedfordshire', 'Berkshire', 'Buckinghamshire', 'Cambridgeshire', 'Cheshire', 'Cleveland', 'Cornwall', 'Coventry', 'Cumbria', 'Derbyshire', 'Devon', 'Dorset', 'Durham', 'East-Sussex', 'Essex', 'Gloucestershire', 'Hampshire', 'Herefordshire', 'Hertfordshire', 'Isle-of-Wight', 'Kent', 'Lancashire', 'Leicestershire', 'Lincolnshire', 'London', 'Merseyside', 'Middlesex', 'Norfolk', 'Northamptonshire', 'Northumberland', 'North-Humberside', 'North-Yorkshire', 'Nottinghamshire', 'Oxfordshire', 'Rutland', 'Shropshire', 'Somerset', 'South-Humberside', 'South-Yorkshire', 'Staffordshire', 'Suffolk', 'Surrey', 'Tyne-and-Wear', 'Warwickshire', 'West-Midlands', 'West-Sussex', 'West-Yorkshire', 'Wiltshire', 'Worcestershire']
client = discord.Client()
file = open("cities.txt","r")
inside = file.read() #this text file is used to store where the user lives
city = str(inside)# to get information about weather and temperature
file.close()
### I got this code from https://pythonprogramming.net/discordpy-basic-bot-tutorial-introduction/
@client.event #and i addapted and added to it to suit our needs
async def on_ready():
print ("Bot is up and running!")
@client.event
async def on_message(message):
if message.author == client.user:
return
elif "hello" in message.content.lower():
await message.channel.send("Hi")
return
elif "how are you" in message.content.lower():
await message.channel.send("Good, how are you?")
return
elif "good" in message.content.lower():
await message.channel.send("That's good")
return
elif "time" in message.content.lower():
await message.channel.send(help.time())
return
elif "date" in message.content.lower() and "shorthand" not in message.content.lower():
await message.channel.send(help.dateLonghand())
return
elif "shorthand" in message.content.lower():
await message.channel.send(help.dateShorthand())
return
elif "help" in message.content.lower():
await message.channel.send(help.help())
return
elif "extra" in message.content.lower():
await message.channel.send(help.extraHelp())
return
elif "weather" in message.content.lower():
file = open("cities.txt","r")
inside = file.read()
city = str(inside)
file.close()
if city != "\n":
await message.channel.send(weather.weather(city))
else: #this makes sure you have entered a city
await message.channel.send("What city are you in?")
return
elif "temp" in message.content.lower():
file = open("cities.txt","r")
inside = file.read()
city = str(inside)
file.close()
if city != "\n":
await message.channel.send(weather.temp(city))
else:
await message.channel.send("What city are you in?")
return
for i in range(len(cities)):
if cities[i] in message.content.lower():
file = open("cities.txt","w")
file.write(str(message.content))
file.close()
await message.channel.send("thank you, please retype your initial question")
return
else:
await message.channel.send("Sorry, I did not understand your message")
#this is the code for my own server becuase I have no controls on DBBJ
client.run("NzgxMjYyODg3NzkxODg2MzQ2.X77Fww.bMtQZRR3368AGVqzk8D3RDsZL5I")