@pixel-fx/discord-connector
TypeScript icon, indicating that this package has built-in type declarations

0.2.6 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i @pixel-fx/discord-connector

Weekly Downloads

2

Version

0.2.6

License

MIT

Unpacked Size

29.8 MB

Total Files

31

Last publish

Collaborators

  • pixel-fx