Reputation: 184
I am developing a web app with a complementary Discord bot. Currently, because I use Node for both, they are in the same project and share the same database connection with Mongoose. I can access the bot in the routes of the web app by requiring it as a module but it's rather clunky.
Is there a way I can send information back and forth between the bot program and the web server? I would just need to be send data like { "action": "send_message", "text": "hello world", etc.}
back and forth, and they would be running on the same computer.
Upvotes: 1
Views: 1253
Reputation: 1639
You can set up a REST Api in your Node app and have your discord bot communicate through it. At a glance, the API might have a route:
POST /v1/messages
which accepts an HTTP body containing { "text": "hello world" }
etc.
There are many HTTP server modules for Node, express
being the most popular. Happy coding!
Upvotes: 1