How to use discord-rpc - 10 common examples

To help you get started, we’ve selected a few discord-rpc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angeloanan / MPC-DiscordRPC / index.js View on Github external
function initRPC(clientID) {
	rpc = new Client({ transport: 'ipc' });
	rpc.on('ready', () => {
		clearInterval(discordRPCLoop);
		mediaEmitter.emit('discordConnected');
		rpc.transport.once('close', async () => {
			await destroyRPC();
			log.error('ERROR: Connection to Discord client was closed. Trying again in 10 seconds...');
			mediaEmitter.emit('discordDisconnected');
			discordRPCLoop = setInterval(initRPC, 10000, clientID);
		});
	});

	// Log in to the RPC server on Discord client, and check whether or not it errors.
	rpc.login(clientID).catch(() => {
		log.warn('WARN: Connection to Discord has failed. Trying again in 10 seconds...');
	});
}
github Azure-Agst / switchcord / main.js View on Github external
});
}

app.on('ready', createWindow);

app.on('window-all-closed', () => {
  app.quit();
});

app.on('activate', () => {
  if (mainWindow === null)
    createWindow();
});

// only needed for discord allowing spectate, join, ask to join
DiscordRPC.register(ClientId);

const rpc = new DiscordRPC.Client({ transport: 'ipc' });
const startTimestamp = new Date();

async function setActivity() {
  if (!rpc || !mainWindow)
    return;

  var gameid = await mainWindow.webContents.executeJavaScript('window.game');
  var gamename = await mainWindow.webContents.executeJavaScript('window.gamename');
  var gamestate = await mainWindow.webContents.executeJavaScript('window.gamestate');

  if (gameid == "home") {
    rpc.setActivity({
      details: `At Home Menu`,
      startTimestamp,
github Pupix / rift-explorer / app.js View on Github external
restartLCUWithOverride,
} = require('./util');

const connector = new LCUConnector();
const { app, dialog } = electron;
const { BrowserWindow } = electron;

const root = `${__dirname}/app`;

// Checking if the running executable is called electron
// seems to be the most straightforward to do this
// https://stackoverflow.com/a/39395885/4895858
const isDev = process.execPath.search('electron') !== -1;

const clientId = '616399159322214425';
const rpc = new DiscordRPC.Client({ transport: 'ipc' });
const startTimestamp = new Date();

let LCURestarted = false;

app.commandLine.appendSwitch('--ignore-certificate-errors');

app.on('ready', () => {
    let mainWindow = null;
    let windowLoaded = false;
    let LCUData = null;

    mainWindow = new BrowserWindow({
        center: true,
        height: 720,
        show: false,
        width: 1280,
github Guerra24 / firefox-discord / server.js View on Github external
const parse = require('parse-duration');
const moment = require('moment');
const express = require('express');
const DiscordRPC = require('discord-rpc');
const client = new DiscordRPC.Client({transport : 'ipc'});
const app = express();

// Express server
app.use(express.json());

function setRP(type, tabTitle, tabURL, iconName) {
	if (type === 'normal') {
		if (iconName) {
			client.setActivity({
				details : `${tabTitle}`,
				state : `${tabURL}`,
				// startTimestamp: moment(new Date()).add(parse("-0s"), "ms").toDate(),
				largeImageKey : `${iconName}`,
				smallImageKey : 'firefox-small',
				smallImageText : 'Firefox',
				instance : false,
github samuelmaddock / metastream / app / browser / vendor / discord.ts View on Github external
const init = async () => {
  const clientId = process.env.DISCORD_CLIENT_ID
  if (!clientId) {
    throw new Error('Discord Client ID not configured.')
  }

  DiscordRPC.register(clientId)

  // Register application protocol for invite launcher
  discordRegister(clientId).catch(err => log.error(err))

  const rpc = new DiscordRPC.Client({ transport: 'ipc' })
  discordRpc = rpc

  rpc.once('ready', () => {
    connected = true
    log.info('Discord RPC ready', discordRpc.user)

    const send = (eventName: string, ...args: any[]) => {
      BrowserWindow.getAllWindows().forEach(win => {
        win.webContents.send(eventName, ...args)
      })
    }
github scripthubteam / DiscordCustomRP / main.js View on Github external
if(fs.existsSync("./config.json") === false){
  let data = `{\n"textCfg": {\n"details": "Oh, hi",\n"state": "This is DiscordCustomRP"\n},\n"imageCfg": {\n"smallKey": "a_small_mari",\n"smallText": "Mari (small text)",\n"largeKey": "a_large_mari",\n"largeText": "Mari (large text)"\n},\n"timeCfg": {\n"timeType": "none",\n"whatTime": "0m"\n},\n\n"clientID": "463437134137655298"\n}`.toString()
  console.error("Configutarion Error!".bgRed)
  console.error("It is not possible to obtain information with the file \"config.json\". This is because the file does not exist.")
  console.warn(`We have recreated the "config.example.json" file with the default data, restart DiscordCustomRP to confirm that you will use these fields. You can modify them later!`.bgGreen)
  fs.writeFileSync("config.example.json", data)
  process.exit()
}

let config = require("./config.json")
const ClientId = config.clientID;
var openTimestamp

DiscordRPC.register(ClientId);

const rpc = new DiscordRPC.Client({
  transport: 'ipc'
});

async function setActivity() {
  if (!rpc)
    return;

  
  var activity = {
    details: config.textCfg.details,
    state: config.textCfg.state,
    smallImageKey: config.imageCfg.smallKey,
    smallImageText: config.imageCfg.smallText,
    largeImageKey: config.imageCfg.largeKey,
    largeImageText: config.imageCfg.largeText,
    instance: false
github scripthubteam / DiscordCustomRP / main.js View on Github external
if(fs.existsSync("./config.json") === false){
  let data = `{\n"textCfg": {\n"details": "Oh, hi",\n"state": "This is DiscordCustomRP"\n},\n"imageCfg": {\n"smallKey": "a_small_mari",\n"smallText": "Mari (small text)",\n"largeKey": "a_large_mari",\n"largeText": "Mari (large text)"\n},\n"timeCfg": {\n"timeType": "none",\n"whatTime": "0m"\n},\n\n"clientID": "463437134137655298"\n}`.toString()
  console.error("Configutarion Error!".bgRed)
  console.error("It is not possible to obtain information with the file \"config.json\". This is because the file does not exist.")
  console.warn(`We have recreated the "config.example.json" file with the default data, restart DiscordCustomRP to confirm that you will use these fields. You can modify them later!`.bgGreen)
  fs.writeFileSync("config.example.json", data)
  process.exit()
}

let config = require("./config.json")
const ClientId = config.clientID;
var openTimestamp

DiscordRPC.register(ClientId);

const rpc = new DiscordRPC.Client({
  transport: 'ipc'
});

async function setActivity() {
  if (!rpc)
    return;

  
  var activity = {
    details: config.textCfg.details,
    state: config.textCfg.state,
    smallImageKey: config.imageCfg.smallKey,
    smallImageText: config.imageCfg.smallText,
    largeImageKey: config.imageCfg.largeKey,
github PreMiD / PreMiD / src / presences / Twitch.js View on Github external
async function tryLogin() {
  TWITCHRPC = new DiscordRPC.Client({ transport: "ipc" });
  TWITCHRPC.login({ clientId: twitch_client_id })
  .catch(err => console.log(`${CONSOLEPREFIX}TWITCHRPC: ${err.message}`))  
  TWITCHRPC.on("ready", () => {
    clearInterval(retryRPCLogin)
    TWITCHRPCREADY = true
  })
}
github PreMiD / PreMiD / src / presences / YouTube.js View on Github external
async function tryLogin() {
  YTRPC = new DiscordRPC.Client({ transport: "ipc" });
  YTRPC.login({ clientId: yt_client_id })
  .catch(err => console.log(`${CONSOLEPREFIX}YTRPC: ${err.message}`))  
  YTRPC.on("ready", () => {
    clearInterval(retryRPCLogin)
    YTRPCREADY = true
  })
}
github Ahriana / YouTube-Music-Desktop / src / renderer.js View on Github external
document.addEventListener('DOMContentLoaded', () => {
    const ipcRenderer = require('electron').ipcRenderer;
    const DiscordRPC = require('discord-rpc');
    const clientId = '460456226090778634';
    let discord = false;
    const rpc = new DiscordRPC.Client({ transport: 'ipc' });
    let last = ['', {}];
    let API = {};
    ipcRenderer.send('load-content');

    ipcRenderer.on('media', (event, store) => {
        if (store === 'nextTrack') {
            return API.nextVideo();
        } else if (store === 'previousTrack') {
            return API.previousVideo();
        } else if (store === 'playPause') {
            const state = API.getPlayerState();
            if (state === 1) {
                return API.pauseVideo();
            } else if (state === 2) { return API.playVideo(); } else {
                return console.log('unhandled player state', state);
            }

discord-rpc

A simple RPC client for Discord

MIT
Latest version published 3 years ago

Package Health Score

51 / 100
Full package analysis

Popular discord-rpc functions