How to use Tensorflow.js for Discord.js chat bot

Hi so i have a working Discord.js bot where i setup some arrays with responses that gets randomly selected and send to the channel if the server when a user mentions his name.

Since this approach is not accurate i wanted to implement Tensorflow.js so my bot’s replies fit what he was asked to or said to in the first place.

I’d need to know how to install tensorflow and or how to use it in my discord bot. I want to train it with custom responses so i can give my bot a custom personality.

Hello there! Thank you for your question :slight_smile: Sorry for the delayed reply due to the weekend and holiday season. This sounds like a really great project! You may want to follow my TensorFlow.js Spam detection tutorial. Even though it is for spam, it may help you understand how to use for other things too such as knowing what sentences refer to the bot vs not etc.

Start with this one:

Then try this one to learn how to retrain a Python model and convert it to JS:

Using these tutorials you can train a model to learn if a sentence is bot related or not for example and then reply accordingly.

We also have a pre-trained model for toxicity detection so if someone is being rude on the Discord server you could send them a warning or such. I would always get a human to verify vs plain blocking right away as no ML system is perfect 100% of the time but at least you can auto flag the message for moderation or such.

For more advanced stuff you may want to check out our Universal Sentence Encoder here:

There is a nice introduction by Yannick who used to be on the TensorFlow.js team here that shows how to use it in a real world use case for understanding language:

And finally feel free to come hang out on discord server too given you are probably a discord user :slight_smile: The TensorFlow.js working group use this to keep in touch between our monthly meetings but some content folk share is useful to all (events, new demos, etc) to just keep in touch :slight_smile:

Hello Jason. I ended up using Google Dialogflow instead. Maybe you’re familiar with it? I got it all working but when i tried adding new intents etc it didnt work in the discord bot. it works on the cloud console/dialogflow website. If feels like the api is not getting the new updated intents.

I added them via the website. Apparently people have issues when adding intents etc via the api.

Indeed I have used Dialog flow many years ago. It is really great tool if you are ok using cloud for the inference and it integrates with many things too like Google Assistant etc - really powerful and makes making assistants pretty easy with the UI.

Unfortunately I have not used it recently so unsure if they changed something. Your best bet would be to find a developer relations engineer on that team who can answer your question quickly. I believe you have to publish it though for it to work beyond the testing sandbox on their website if I remember correctly.

As it is holidays right now you may have to wait until the new year as a lot of people are out but maybe you can find someone on LinkedIn or such who may reply who is on the DialogFlow team.

Yeah i posted a question on stackoverflow but i havent gotten any replies yet. imma keep this question updated as soon as i have a solution