Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An easy snippet to generate your Discord bot's Bearer token!
const express = require('express');
const app = express();
const fetch = require('node-fetch');
const client_id = 'CLIENT_UI'; //can be found in the developer portal
const redirect_uri = 'http://localhost:8000/home';
const client_secret = 'CLIENT_SECRET'; //can be also found in the developer portal
const scope = 'identify'; // set the redirect_uri in your OAuth2 section and use the identify scope in your browser.
app.get('/authorize', (req, res) => {
res.redirect(`https://discord.com/api/oauth2/authorize?client_id=${client_id}&redirect_uri=${encodeURIComponent(redirect_uri)}&response_type=code&scope=${encodeURIComponent(scope)}`)
});
app.get('/home', async (req, res) => {
res.send('Done.')
fetch('https://discord.com/api/oauth2/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
client_id: client_id,
client_secret: client_secret,
code: req.query.code,
grant_type: 'authorization_code',
redirect_uri: redirect_uri,
scope: scope,
}),
})
.then(response => response.json())
.then((data) => console.log(data));
});
app.listen(8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment