const { Client } = require('discord-rpc/browser');
const clientID = '187406016902594560';
const scopes = ['rpc', 'rpc.api', 'messages.read'];
// This demonstrates discord's implicit oauth2 flow
// http://discordapi.com/topics/oauth2#implicit-grant
const params = new URLSearchParams(document.location.hash.slice(1));
const accessToken = params.has('access_token') ?
params.get('access_token') : localStorage.accessToken;
localStorage.accessToken = accessToken;
if (!accessToken) {
// Redirect to discord to get an access token
document.location.href = `https://discordapp.com/oauth2/authorize?response_type=token&client_id=${clientID}&scope=${scopes.join(' ')}`;
}
const client = new Client({ transport: 'websocket' });
client.on('ready', () => {
console.log('Logged in as', client.application.name);
console.log('Authed for user', client.user.tag);
client.selectVoiceChannel('81384788862181376');
});
// Log in to RPC with client id and access token
client.login(clientID, { accessToken, scopes });
rich-presence-test
1.0.0 • Public • PublishedPackage Sidebar
Install
npm i rich-presence-test
Repository
Homepage
Weekly Downloads
2
Version
1.0.0
License
MIT
Unpacked Size
177 kB
Total Files
14