I need my Discord Bot handling GET and POST requests for an external website
I want my Discord Bot handling GET and POST requests, to control some features of my Bot with a dashboard. Knowing that my Bot is hosted in a different server than my future dashboard.
Someone talked about setting a RESTFul API but after some researches I don't really know how to do it and if it will really help me. I can't say if another ways are possible.
I'm using node.js and the library discord.js
node.js httprequest discord.js
add a comment |
I want my Discord Bot handling GET and POST requests, to control some features of my Bot with a dashboard. Knowing that my Bot is hosted in a different server than my future dashboard.
Someone talked about setting a RESTFul API but after some researches I don't really know how to do it and if it will really help me. I can't say if another ways are possible.
I'm using node.js and the library discord.js
node.js httprequest discord.js
1
Look into Express and read some tutorials about it, can't say much more than that.
– MadWard
Jan 18 at 20:13
What @MadWard said and can you show what you already tried, what errors you get,... SA is not made for broad questions like this, you will have to be more specific. You also should look at tools like curl and Postman to learn how to interact with API's.
– Ilyas Deckers
Jan 18 at 20:25
add a comment |
I want my Discord Bot handling GET and POST requests, to control some features of my Bot with a dashboard. Knowing that my Bot is hosted in a different server than my future dashboard.
Someone talked about setting a RESTFul API but after some researches I don't really know how to do it and if it will really help me. I can't say if another ways are possible.
I'm using node.js and the library discord.js
node.js httprequest discord.js
I want my Discord Bot handling GET and POST requests, to control some features of my Bot with a dashboard. Knowing that my Bot is hosted in a different server than my future dashboard.
Someone talked about setting a RESTFul API but after some researches I don't really know how to do it and if it will really help me. I can't say if another ways are possible.
I'm using node.js and the library discord.js
node.js httprequest discord.js
node.js httprequest discord.js
asked Jan 18 at 20:08
AnkommAnkomm
103110
103110
1
Look into Express and read some tutorials about it, can't say much more than that.
– MadWard
Jan 18 at 20:13
What @MadWard said and can you show what you already tried, what errors you get,... SA is not made for broad questions like this, you will have to be more specific. You also should look at tools like curl and Postman to learn how to interact with API's.
– Ilyas Deckers
Jan 18 at 20:25
add a comment |
1
Look into Express and read some tutorials about it, can't say much more than that.
– MadWard
Jan 18 at 20:13
What @MadWard said and can you show what you already tried, what errors you get,... SA is not made for broad questions like this, you will have to be more specific. You also should look at tools like curl and Postman to learn how to interact with API's.
– Ilyas Deckers
Jan 18 at 20:25
1
1
Look into Express and read some tutorials about it, can't say much more than that.
– MadWard
Jan 18 at 20:13
Look into Express and read some tutorials about it, can't say much more than that.
– MadWard
Jan 18 at 20:13
What @MadWard said and can you show what you already tried, what errors you get,... SA is not made for broad questions like this, you will have to be more specific. You also should look at tools like curl and Postman to learn how to interact with API's.
– Ilyas Deckers
Jan 18 at 20:25
What @MadWard said and can you show what you already tried, what errors you get,... SA is not made for broad questions like this, you will have to be more specific. You also should look at tools like curl and Postman to learn how to interact with API's.
– Ilyas Deckers
Jan 18 at 20:25
add a comment |
1 Answer
1
active
oldest
votes
You can use express to do different things for GET and POST
Use POST for the webserver requests as the browsers use GET.
Note: the bot would run this to serve the webserver
var express = require('express');
var app = express();
var data = '{"example":{"online":true,"status":"200"}}';
app.get('/', function(req, res) {
res.send('<html><head><script>window.location.href = 'https://google.com/'</script></head><body>You shouldn't be here! <a href='https://google.com'>Exit</a></body></html>');
/** Redirect the browser to google with window.location.href
* Change this to your site */
});
app.post('/', function(req, res) {
/** You could add some auth code here but
* if your sending it all to the client there isn't much of a difference
* because people could read it from the website. */
res.type('json');
res.json(data);
/* Webserver --> Bot */
res.end();
});
app.listen(8080);
console.log('API Online');
You will have to use setInterval(() => {}, 15000);
to update the data variable and you need to parse the data on the client.
XMLHttpRequest should work well enough for that
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54260773%2fi-need-my-discord-bot-handling-get-and-post-requests-for-an-external-website%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use express to do different things for GET and POST
Use POST for the webserver requests as the browsers use GET.
Note: the bot would run this to serve the webserver
var express = require('express');
var app = express();
var data = '{"example":{"online":true,"status":"200"}}';
app.get('/', function(req, res) {
res.send('<html><head><script>window.location.href = 'https://google.com/'</script></head><body>You shouldn't be here! <a href='https://google.com'>Exit</a></body></html>');
/** Redirect the browser to google with window.location.href
* Change this to your site */
});
app.post('/', function(req, res) {
/** You could add some auth code here but
* if your sending it all to the client there isn't much of a difference
* because people could read it from the website. */
res.type('json');
res.json(data);
/* Webserver --> Bot */
res.end();
});
app.listen(8080);
console.log('API Online');
You will have to use setInterval(() => {}, 15000);
to update the data variable and you need to parse the data on the client.
XMLHttpRequest should work well enough for that
add a comment |
You can use express to do different things for GET and POST
Use POST for the webserver requests as the browsers use GET.
Note: the bot would run this to serve the webserver
var express = require('express');
var app = express();
var data = '{"example":{"online":true,"status":"200"}}';
app.get('/', function(req, res) {
res.send('<html><head><script>window.location.href = 'https://google.com/'</script></head><body>You shouldn't be here! <a href='https://google.com'>Exit</a></body></html>');
/** Redirect the browser to google with window.location.href
* Change this to your site */
});
app.post('/', function(req, res) {
/** You could add some auth code here but
* if your sending it all to the client there isn't much of a difference
* because people could read it from the website. */
res.type('json');
res.json(data);
/* Webserver --> Bot */
res.end();
});
app.listen(8080);
console.log('API Online');
You will have to use setInterval(() => {}, 15000);
to update the data variable and you need to parse the data on the client.
XMLHttpRequest should work well enough for that
add a comment |
You can use express to do different things for GET and POST
Use POST for the webserver requests as the browsers use GET.
Note: the bot would run this to serve the webserver
var express = require('express');
var app = express();
var data = '{"example":{"online":true,"status":"200"}}';
app.get('/', function(req, res) {
res.send('<html><head><script>window.location.href = 'https://google.com/'</script></head><body>You shouldn't be here! <a href='https://google.com'>Exit</a></body></html>');
/** Redirect the browser to google with window.location.href
* Change this to your site */
});
app.post('/', function(req, res) {
/** You could add some auth code here but
* if your sending it all to the client there isn't much of a difference
* because people could read it from the website. */
res.type('json');
res.json(data);
/* Webserver --> Bot */
res.end();
});
app.listen(8080);
console.log('API Online');
You will have to use setInterval(() => {}, 15000);
to update the data variable and you need to parse the data on the client.
XMLHttpRequest should work well enough for that
You can use express to do different things for GET and POST
Use POST for the webserver requests as the browsers use GET.
Note: the bot would run this to serve the webserver
var express = require('express');
var app = express();
var data = '{"example":{"online":true,"status":"200"}}';
app.get('/', function(req, res) {
res.send('<html><head><script>window.location.href = 'https://google.com/'</script></head><body>You shouldn't be here! <a href='https://google.com'>Exit</a></body></html>');
/** Redirect the browser to google with window.location.href
* Change this to your site */
});
app.post('/', function(req, res) {
/** You could add some auth code here but
* if your sending it all to the client there isn't much of a difference
* because people could read it from the website. */
res.type('json');
res.json(data);
/* Webserver --> Bot */
res.end();
});
app.listen(8080);
console.log('API Online');
You will have to use setInterval(() => {}, 15000);
to update the data variable and you need to parse the data on the client.
XMLHttpRequest should work well enough for that
answered Jan 18 at 21:22
AkiraMiuraAkiraMiura
5414
5414
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54260773%2fi-need-my-discord-bot-handling-get-and-post-requests-for-an-external-website%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Look into Express and read some tutorials about it, can't say much more than that.
– MadWard
Jan 18 at 20:13
What @MadWard said and can you show what you already tried, what errors you get,... SA is not made for broad questions like this, you will have to be more specific. You also should look at tools like curl and Postman to learn how to interact with API's.
– Ilyas Deckers
Jan 18 at 20:25