Permalink
Cannot retrieve contributors at this time
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?
ChatBot/CSVSearchDiscord.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
38 lines (28 sloc)
1.38 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import discord | |
import csv | |
from discord.ext import commands | |
bot = commands.Bot(command_prefix='!', description='A bot to help the user choose a car.') | |
# Code was found from an example in the discord.py documentation, I added the feature to change the bots presence. | |
@bot.event | |
async def on_ready(): | |
print('Logged in as') | |
print(bot.user.name) | |
print(bot.user.id) | |
activity = discord.Activity(name='You Pick A Car', type=discord.ActivityType.watching) | |
await bot.change_presence(activity=activity) | |
bot.remove_command('help') | |
# End of example code from discord.py documentation that I edited slightly. | |
# Code to search the csv file was wrote by roshan and I intergrated it into discord using different functions from the discord.py docuemtation | |
@bot.event | |
async def on_message(message): | |
with open('C:/Users/chadw/PycharmProjects/PythonChatBot/cardatabase/2019.csv', 'r') as csv_file: | |
csv_reader = csv.reader(csv_file) | |
messageLower = message.content.lower() | |
for line in csv_reader: | |
if message.author == bot.user: | |
return | |
else: | |
if messageLower == line[1] or messageLower == line[2] or messageLower in line[3]: | |
await message.channel.send(line[0] + " " + line[1] + " " + line[2]) | |
# End of code from roshan that I intergrated to discord. | |
bot.run('') |