How to use the discord-rpc.Client function in discord-rpc

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 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 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 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);
            }
github CorySanin / Kitten-for-CSGO / richpresence.js View on Github external
/**
https://discordapp.com/developers/docs/rich-presence/how-to#updating-presence-update-presence-payload-fields
https://github.com/discordjs/RPC/blob/master/example/main.js
*/
const { shell } = require('electron')
const DiscordRPC = require('discord-rpc')
const clientId = '508480505583370272'

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

let state = {}
let discordrptoggle = null

function setDiscordToggle(toggle){
  discordrptoggle = toggle
}

function updateInfo(data, appyToExisting){
  if(!appyToExisting){
    state = {}
  }
  for(let key in data){
    state[key] = data[key]
  }
}
github BrianPetkovsek / discord-youtube / main.js View on Github external
const {BrowserWindow, app} = require('electron');
const {Client} 			   = require('discord-rpc');
const widevine             = require('electron-widevinecdm');
const rpc                  = new Client({transport: 'ipc'});

const {injectRun}		   = require('youtube-js')
const pack 			   	   = require("./package.json");
const version 			   = pack.version;
const name 			   	   = pack.name;
const author 			   = pack.author;
const github_repository    = pack.github_repository;

const updateUHTM = process.cwd()+'/updating.html'

String.prototype.format = function() {
  a = this;
  for (k in arguments) {
    a = a.replace("{" + k + "}", arguments[k])
  }
  return a

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