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/textSimilarityDiscord.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
48 lines (34 sloc)
1.36 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 requests | |
from discord.ext import commands | |
bot = commands.Bot(command_prefix='!', description='A bot to help the user choose a car.') | |
# Example from discord.py documentation that I added the change precence function | |
@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 modified example from discord.py | |
# Text similarity api from Roshan that i intergrated to discord. | |
@bot.event | |
async def on_message(message): | |
if message.author == bot.user: | |
return | |
else: | |
url = "https://text-similarity-calculator.p.rapidapi.com/stringcalculator.php" | |
x = "Im looking for a brand new family car" | |
y = message.content | |
querystring = {"ftext": x, "stext": y} | |
headers = { | |
'x-rapidapi-host': "text-similarity-calculator.p.rapidapi.com", | |
'x-rapidapi-key': "" | |
} | |
response = requests.request("GET", url, headers=headers, params=querystring) | |
z = len(response.text) | |
y = response.text[498:z - 2] | |
await message.channel.send(y) | |
# End of text similarty api from Roshan that I intergrated | |
bot.run('') |