/node-discord-game

The Discord Game SDK for Electron.js

Primary LanguageC

Discord Game SDK

Node CI Status FOSSA Status

This is node.js module for Electron to integrate with Discord.

Requirements

  • Node.js 11+
  • Electron 6.0+

Windows Setup

The Windows is required to add dll to project root, please copy sdk\{ARCH}\discord_game_sdk.dll to your project folder to ensure your Electron can access SDK correctly.

Usage

Before using this module, you have to go to Discord Developer to create an application.

Discord

create()

Initialize Discord.

const Discord = require('discord-game');

const isRequireDiscord = true;
Discord.create('Client ID', isRequireDiscord);
// => true

version

Get Discord Game SDK Version

runCallback()

Resolve Discord's async behavior and call the callback;

const Discord = require('discord-game');

const isRequireDiscord = true;
Discord.create('Client ID', isRequireDiscord);

setInterval(function() {
  Discord.runCallback(); // => true
}, 1000/60)

Application

locale

Get the current locale

branch

Get the current branch

getOAuth2Token()

Get the user OAuth2 Token.

const Discord = require('discord-game');

const isRequireDiscord = true;
Discord.create('Client ID', isRequireDiscord);

Discord.Application
       .getOAuth2Token()
       .then(function(token) { console.log('Token is', token) });

setInterval(function() {
  Discord.runCallback(); // => true
}, 1000/60)

Activity (aka Rich Presence)

update

Update user's rich presence.

const Discord = require('discord-game');

const isRequireDiscord = true;
Discord.create('Client ID', isRequireDiscord);

// All property are optional
const activity = {
  details: 'Details',
  state: 'State',
  assets: {
    largeImage: 'large',
    largeText: 'Large',
    samllImage: 'small',
    smallText: 'Small'
  },
  timestamps: {
    startAt: new Date(),
    endAt: new Date()
  },
  secrets: {
    match: 'match',
    join: 'join',
    spectate: 'spectate'
  },
  party: {
    id: 'id',
    currentSize: 1,
    maxSize: 5
  }
}
const start_at = new Date();
Discord.Activity
       .update(activity)
       .then(function() { console.log('Rich Presence updated') });

setInterval(function() {
  Discord.runCallback(); // => true
}, 1000/60)

clear

Clear user's rich presence.

Discord.Activity.clear()

License

FOSSA Status