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
import discord
from discord.ext import commands
import asyncio
import nltk
from nltk.stem import PorterStemmer, WordNetLemmatizer
from nltk.tokenize import word_tokenize
from ad_nltk import lemmatize_texts, find_synonyms
TOKEN = 'NTA1Nzc5MjQxNzk1OTc3MjI2.DrdHTw.Y4X-A0MntmN9riVEpaFC55Nv3Wk'
client = commands.Bot(command_prefix = ['.', '!'])
#nltk
stemmer = PorterStemmer()
#source: discord chatbot tutorials
@client.event
async def on_ready():
"""Shows the name and id of the chatbot when it is ready."""
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
#s: Lucas Kumara
@client.command()
async def callBack(*args):
"""Echoes messages of other users in the channel."""
output = ''
for word in args:
output += word
output += ' '
await asyncio.sleep(2)
await client.say(output)
@client.command()
async def hello():
"""Echoes 'hello' back to user."""
await asyncio.sleep(2)
await client.say("Hello!")
#P
@client.command()
async def logout():
"""Logs chatbot out"""
print("Logging out bot")
await client.say("See you later, loser!")
await client.close()
@client.event
async def on_message(message):
lemmatized_tokens = lemmatize_texts(message.content)
syns_found = find_synonyms(lemmatized_tokens)
print(syns_found)
"""Displays message and message author on terminal"""
if message.author != client.user:
print(str(message.author) + " has written " + "'" + str(message.content) + "'" + ".")
#source: sample.py
"""Prevents bot from responding to its own messages."""
if message.author == client.user:
return
#P
"""Detects lemma 'marry' in message channel and responds to it."""
if "marry" in syns_found:
msg = "Wait, what's going on? {0.author.mention}".format(message)
await client.send_message(message.channel, msg)
"""Detects lemma 'hot in message channel and responds to it."""
if "hot" in syns_found:
msg = "I don't know how to cool you down."
await client.send_message(message.channel, msg)
await client.process_commands(message)
client.run(TOKEN)