Skip to content

Instantly share code, notes, and snippets.

@letthedataconfess
Last active January 21, 2022 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save letthedataconfess/da5df1e519886bb28fecd44d00d664ae to your computer and use it in GitHub Desktop.
Save letthedataconfess/da5df1e519886bb28fecd44d00d664ae to your computer and use it in GitHub Desktop.
#importing some important library
import os
import discord
#importing the library to which will help us to get the negative , positive score
#VADER ( Valence Aware Dictionary for Sentiment Reasoning) is a model used for text sentiment analysis that is sensitive to both polarity (positive/negative) and intensity (strength) of emotion. It is available in the NLTK package and can be applied directly to unlabeled text data.
#VADER sentimental analysis relies on a dictionary that maps lexical features to emotion intensities known as sentiment scores. The sentiment score of a text can be obtained by summing up the intensity of each word in the text.
#For example- Words like ‘love’, ‘enjoy’, ‘happy’, ‘like’ all convey a positive sentiment. Also VADER is intelligent enough to understand the basic context of these words, such as “did not love” as a negative statement. It also understands the emphasis of capitalization and punctuation, such as “ENJOY”
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
sid_obj = SentimentIntensityAnalyzer()
# A function that checks if a given text is a positive or a negative review/comment
def check(text):
sentiment_dict = sid_obj.polarity_scores(text)
neg_score = sentiment_dict['neg']*100
pos_socre = sentiment_dict['pos']*100
if pos_socre>neg_score:
return 'Positive'
else:
return 'Negative'
# the token which we created in Repl step 7
my_secret = os.environ['TOKEN']
# instance of a client/user
client=discord.Client()
@client.event# makes a registration for a event by the client
#And this is an async library so things discord.py so things are done with a call back it is a function when something else happens so in this code we are going to use the on_ready event
async def on_ready():
print('We logged in as {0.user}'.format(client))
greet=['$hello','$hi','$hey','$hii']
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content in greet:
await message.channel.send('Hello! Write your review')
elif message.content.startswith("$"):# we need to start the text,review with a $ to get the code
sentiment= check(message.content)#calling the check funtion
if sentiment=="Positive":
await message.channel.send('Good review')
else:
await message.channel.send('Bad review')
client.run(my_secret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment