let { CLIENT_ID,
CLIENT_SECRET,
TOKEN,
} = JSON.parse(fs.readFileSync('./privates.json', 'utf8'))
var authapp = express()
authapp.get('/', (req, res) => {
let code = req.originalUrl.split("=")[1]
console.log(code)
let postData = querystring.stringify({
'grant_type': 'authorization_code',
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'code': code,
'redirect_uri': redirecturi,
'scope': 'identify'
})
let reqOptions = {
host: "discordapp.com",
path: `/api/oauth2/token`,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
method: "POST"
}
let tokenGrant = https.request(reqOptions, (res) => {
res.setEncoding('utf8');
res.on('data', (response) => {
console.log(`Response: ${response}`);
});
res.on('end', () => {
console.log('Res end.');
});
})
tokenGrant.on('error', (e) => {
console.error(`Error: ${e.message}`);
});
tokenGrant.write(postData);
tokenGrant.end();```