discordrpc

package module
v0.0.0-...-2039603 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 10 Imported by: 0

README

PkgGoDev

An implementation of Discord's rich presence in Golang for Linux, macOS and Windows

Forked from rich-go

See the reference link at the top for example usage

Documentation

Index

Constants

View Source
const (
	// DispatchCommand event dispatch
	DispatchCommand command = "DISPATCH"

	// AuthorizeCommand used to authorize a new client with your app
	AuthorizeCommand command = "AUTHORIZE"

	// AuthenticateCommand used to authenticate an existing client with your app
	AuthenticateCommand command = "AUTHENTICATE"

	// GetGuildCommand used to retrieve guild information from the client
	GetGuildCommand command = "GET_GUILD"

	// GetGuildsCommand used to retrieve a list of guilds from the client
	GetGuildsCommand command = "GET_GUILDS"

	// GetChannelCommand used to retrieve channel information from the client
	GetChannelCommand command = "GET_CHANNEL"

	// GetChannelsCommand used to retrieve a list of channels for a guild from the client
	GetChannelsCommand command = "GET_CHANNELS"

	// SubscribeCommand used to subscribe to an RPC event
	SubscribeCommand command = "SUBSCRIBE"

	// UnSubscribeCommand used to unsubscribe from an RPC event
	UnSubscribeCommand command = "UNSUBSCRIBE"

	// SetUserVoiceSettingsCommand used to change voice settings of users in voice channels
	SetUserVoiceSettingsCommand command = "SET_USER_VOICE_SETTINGS"

	// SelectVoiceChannelCommand used to join or leave a voice channel, group dm, or dm
	SelectVoiceChannelCommand command = "SELECT_VOICE_CHANNEL"

	// GetSelectedVoiceChannelCommand used to get the current voice channel the client is in
	GetSelectedVoiceChannelCommand command = "GET_SELECTED_VOICE_CHANNEL"

	// SelectTextChannelCommand used to join or leave a text channel, group dm, or dm
	SelectTextChannelCommand command = "SELECT_TEXT_CHANNEL"

	// GetVoiceSettingsCommand used to retrieve the client's voice settings
	GetVoiceSettingsCommand command = "GET_VOICE_SETTINGS"

	// SetVoiceSettingsCommand used to set the client's voice settings
	SetVoiceSettingsCommand command = "SET_VOICE_SETTINGS"

	// CaptureShortcutCommand used to capture a keyboard shortcut entered by the user
	CaptureShortcutCommand command = "CAPTURE_SHORTCUT"

	// SetCertifiedDevicesCommand used to send info about certified hardware devices
	SetCertifiedDevicesCommand command = "SET_CERTIFIED_DEVICES"

	// SetActivityCommand used to update a user's Rich Presence
	SetActivityCommand command = "SET_ACTIVITY"

	// SendActivityJoinInviteCommand used to consent to a Rich Presence Ask to Join request
	SendActivityJoinInviteCommand command = "SEND_ACTIVITY_JOIN_INVITE"

	// CloseActivityRequestCommand used to reject a Rich Presence Ask to Join request
	CloseActivityRequestCommand command = "CLOSE_ACTIVITY_REQUEST"
)

Variables

This section is empty.

Functions

func FindCaseInsensitive

func FindCaseInsensitive(parent, target string) (string, error)

Types

type Activity

type Activity struct {
	Type       int    `json:"type,omitempty"`
	Name       string `json:"name,omitempty"`
	StatusType int    `json:"status_display_type,omitempty"`
	Details    string `json:"details,omitempty"`
	State      string `json:"state,omitempty"`

	Timestamps *Timestamps `json:"timestamps,omitempty"`
	Assets     *Assets     `json:"assets,omitempty"`
	Party      *Party      `json:"party,omitempty"`
	Secrets    *Secrets    `json:"screts,omitempty"`

	Instance bool `json:"instance"`
}

Activity holds the data for discord rich presence https://discord.com/developers/docs/events/gateway-events#activity-object-activity-types

type Args

type Args struct {
	Pid      int       `json:"pid"`
	Activity *Activity `json:"activity,omitempty"`
}

Args seems to contain the most data, Pid here is pandatory

type Assets

type Assets struct {
	LargeImage string `json:"large_image,omitempty"`
	LargeText  string `json:"large_text,omitempty"`
	SmallImage string `json:"small_image,omitempty"`
	SmallText  string `json:"small_text,omitempty"`
}

Assets passes image references for inclusion in rich presence

type Client

type Client struct {
	ClientID string
	Socket   *ipc.Socket
}

Client wrapper for the Discord RPC client

func New

func New(clientid string) (*Client, error)

New sends a handshake in the socket and returns an error or nil and an instance of Client

func (*Client) SetActivity

func (c *Client) SetActivity(activity Activity) error

SetActivity sets the Rich Presence activity for the running application

type Data

type Data struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

Data section of the RPC response

type Epoch

type Epoch struct{ time.Time }

Epoch wrapper around time.Time to ensure times are sent as a unix epoch int

func (Epoch) MarshalJSON

func (t Epoch) MarshalJSON() ([]byte, error)

MarshalJSON converts time.Time to unix time int

type Party

type Party struct {
	ID   string `json:"id"`
	Size []int  `json:"size"` // seems to be element [0] is count and [1] is max
}

Party holds information for the current party of the player

type Secrets

type Secrets struct {
	Join     string `json:"join,omitempty"`
	Spectate string `json:"spectate,emitempty"`
	Match    string `json:"match,omitempty"`
}

Secrets holds secrets for Rich Presence joining and spectating

type Timestamps

type Timestamps struct {
	Start *Epoch `json:"start,omitempty"`
	End   *Epoch `json:"end,omitempty"`
}

Timestamps holds unix timestamps for start and/or end of the game

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL