Hallo,
Ich will für meinen Bot ein Webinterface bauen. Dass was ich hier raus erzielen will, ist dass ich in JS Hallo Welt auf der Website ausgebe. Den Rest schaffe ich selber. Es muss aber Node js sein
You might want to learn expressjs, html and css first.
Little example of Discord OAuth2:
const express = require("express");
const app = express();
const request = require('request');
const clientid = "client id here";
const clientsecret = "client secret here";
const callbacklink = "enter callback link";
const port = process.env.PORT;
app.use(express.static("public"));
const listener = app.listen(port, function() {
console.log("Your app is listening on port " + listener.address().port);
});
app.get("/", (req, res) => {
if (req.query.username && req.query.discrim) {
res.send("<!DOCTYPE html>\n<html>\n<head>\n <title>OAuth2</title>\n</head>\n<body>\n <p>" + decodeURIComponent(req.query.username) + "#" + req.query.discrim + "</p>\n </body>\n</html>")
} else {
res.send(`<!DOCTYPE html>\n<html>\n<head>\n <title>OAuth2</title>\n</head>\n<body>\n <p>\n <a href="https://discordapp.com/api/oauth2/authorize?client_id=` + clientid + `&redirect_uri=` + callbacklink + `&response_type=code&scope=identify">Login</a>\n </p>\n </body>\n</html>`);
}
});
app.get("/callback", (req, res) => {
if (req.query.code) {
try {
request.post({
headers: {'content-type': 'application/x-www-form-urlencoded'},
url: 'https://discordapp.com/api/oauth2/token',
body: "client_id=" + clientid + "&client_secret=" + clientsecret + "&grant_type=authorization_code&code=" + req.query.code + "&redirect_uri=" + callbacklink
}, function(error, response, accesskey) {
let accesskeyarray = JSON.parse(accesskey)
request.get('https://discordapp.com/api/users/@me', {
'auth': {
'bearer': accesskeyarray.access_token
}
}, function(error, response, userinfo) {
if (!error) {
let userinfoarray = JSON.parse(userinfo)
let userid = userinfoarray.id
let username = userinfoarray.username
let discrim = userinfoarray.discriminator
res.redirect("/?username=" + encodeURIComponent(username) + "&discrim=" + discrim)
} else {
res.redirect("/")
}
});
});
} catch(err) {
res.redirect("/")
}
} else {
res.redirect("/")
}
});
app.get("*", (req, res) => {
res.redirect("/")
});
Use google translate I guess.
Rofl
Danke, sie haben mir sehr geholfen. Und dann zum eigentlichen Webinterface, da muss ich dann alles ab app.get("callback", (req, res) => {
Weglassen, und da drüber den Code dann mit dem HTML anpassen, oder?
Do you happen to know English by any chance?
Yes. All the information is given from the callback then sent to the HTML change.
You can try to modify the code in order to save the data using website cookies and making a database.