@heroicgl/discord-rpc
v1.1.0
Published
A simple Discord Rich Presence implementation
Downloads
4
Readme
discord-rpc
A simple Discord Rich Presence implementation
Basic Example:
import RPCClient from '@heroicgl/discord-rpc'
const client = RPCClient.make('your_client_id_here')
if (client) {
client.request({
cmd: 'SET_ACTIVITY',
args: {
pid: process.pid,
activity: { state: 'Some extra info here' }
}
})
}
// Some time later: Closing the connection
if (client) {
client.close()
}
You can send any valid RPC Command
via the request
method, except for SUBSCRIBE
and UNSUBSCRIBE
. Since those two commands involve events that should
also be type-checked, there are special methods for them specifically (subscribe
and unsubscribe
).
Working with Events
Note: We were unable to test this part of the client as it seems to require RPC access (granted only by Discord).
The one exception to this workflow is the READY
event. Due to the architecture of the make
method, this event
will not be emitted. You can instead access it with client.ready_data
.
client.subscribe({ evt: 'GUILD_CREATE' })
client.on('event', (event) => {
// Note that you'll have to filter out the type of the event yourself
if (event.evt === 'GUILD_CREATE') {
// `event` is now a `GUILD_CREATE` event & you'll get type hints
console.log('New guild created:', event.data.name)
}
})