We were curious about applying sentiment analysis tools in different situations, and decided to do so within the context of a Discord server. Since some of us had previous experience attempting to develop a Discord bot, we decided to do so again in order to analyze the sentiment of messages within a channel or from a user, and then represent it visually as well.
What it does
The bot takes any combination of an integer, a user mention, and a text channel within a server, then collects the [integer] most recent applicable(containing text other than a URL, user mention, or text channel) messages from either all users or the mentioned user in the given channel. Default settings are the 100 most recent messages from all users in the current text channel. After collecting the messages, we use VADER sentiment analysis on each one, getting a result in [-1,1], where negative scores represent negative sentiment, and positive scores represent positive sentiment. We then compute a weighted mean and output it along with a graph that visually represents the mean as a combination of a sawtooth wave(for negative sentiment) and a sine wave(for positive sentiment).
How we built it
We used discord.py as our choice of wrapper for the Discord API, using it for argument parsing and message gathering purposes, then used matplotlib.pyplot to obtain the desired function and graph. When parsing messages, we also utilized regex functions within Python to remove URLs, user mentions, and channel mentions from messages, afterwards parsing out messages that were made empty by doing so. Additionally, since the original VADER sentiment lexicon was built in 2014, we appended a set of words that became more commonly-used on the Internet since then, with sentiment ratings from 10 different people as specified in the documentation.
Challenges we ran into
We ran into issues utilizing discord.py for proper argument parsing, which stemmed from trying to work with the limitations of the Discord API. Our method of implementing a weighted mean also ran into issues with low integer values at first, always outputting 0, or 50%, when 1 was the integer argument. There were also issues with formatting the graph in a satisfying way, as the code we used initially generated axes and labels, none of which were needed for a purely visual representation of the mean we obtained.
Accomplishments that we're proud of
We are proud to have made a functional bot that integrates both VADER and pyplot satisfactorily. We've played with bot-making in the past but mostly kept functionality to what could be done entirely through basic Python functions and discord.py and it was truly a rewarding experience to figure out how to connect each part of the program together and create the finished product.
What we learned
We achieved better understanding of discord.py and thus the Discord API from previous attempts, became more comfortable with using Python as a group, and gained insight into how sentiment analysis is done through studying VADER.
What's next for Discord Sentiment Analysis - Vibe Checker
What's next you might ask? We want to expand the scope of the project by analyzing text on a larger level. If possible, we want to take multiple words into account, such as typical phrases, since VADER by default analyzes each word on its own without full context.
For security purposes, in order to work, the bot requires that a .env file containing "DISCORD_TOKEN=token" is in the main folder. This ensures that our token cannot be pasted into other code to access servers that the bot is already in.