DiscordRPC
public class DiscordRPC
An object that manages an RPC connection to Discord through UDS and allows to interact with the Discord API using Swift types and methods.
-
Client ID of your Discord Application, set during
init()
Declaration
Swift
public let clientID: String
-
Client Secret of your Discord Application, set during
init()
Declaration
Swift
public let clientSecret: String?
-
Time limit in milliseconds for a sync command to get a response (default: 1000)
Declaration
Swift
public var cmdTimeout: Int
-
Creates a new DiscordRPC instance using the given
clientID
and optionnalclientSecret
. To get these, go to your Discord Dashboard under OAuth2 section.Declaration
Swift
public init(clientID: String, clientSecret: String? = nil)
-
Init connection to the Discord RPC API, this will trigger: - on success: an
EventReady
event on theconnectHandler
- on failure: anEventClose
event on thedisconnectHandler
Throws
RPCError.appSandboxed
: If the current application is sandboxedRPCError.socketCreation
: If the creation of the socket failedRPCError.udsNotFound
: If unable to find the Discord UDS file
Declaration
Swift
public func connect() throws
-
Disconnect from the Discord RPC API.
Declaration
Swift
public func disconnect()
-
Undocumented
Declaration
Swift
public func authorize( oAuth2Scopes: [OAuth2Scope], username: String? = nil, rpcToken: String? = nil) throws -> ResponseAuthorize
-
Undocumented
Declaration
Swift
public func authorizeAsync( oAuth2Scopes: [OAuth2Scope], username: String? = nil, rpcToken: String? = nil) throws -> String
-
Undocumented
Declaration
Swift
public func authenticate(accessToken: String) throws -> ResponseAuthenticate
-
Undocumented
Declaration
Swift
public func authenticateAsync(accessToken: String) throws -> String
-
Undocumented
Declaration
Swift
public func subscribe(event: EventType, id: String? = nil) throws -> ResponseSubscribe
-
Undocumented
Declaration
Swift
public func subscribeAsync(event: EventType, id: String? = nil) throws -> String
-
Undocumented
Declaration
Swift
public func unsubscribe(event: EventType, id: String? = nil) throws -> ResponseUnsubscribe
-
Undocumented
Declaration
Swift
public func unsubscribeAsync(event: EventType, id: String? = nil) throws -> String
-
Undocumented
Declaration
Swift
public func fetchAccessToken(code: String, timeout: Int? = 10000, redirectURI: String = "") throws -> AccessToken
-
Undocumented
Declaration
Swift
public func fetchRPCToken(timeout: Int? = 10000) throws -> RPCToken
-
Undocumented
Declaration
Swift
public func onConnect( handler: @escaping (_ rpc: DiscordRPC, _ eventReady: EventReady) -> Void )
-
Undocumented
Declaration
Swift
public func onDisconnect( handler: @escaping (_ rpc: DiscordRPC, _ closeError: EventClose) -> Void )
-
Undocumented
Declaration
Swift
public func onResponse( handler: @escaping (_ rpc: DiscordRPC, _ nonce: String, _ commandType: CommandType, _ response: Data) -> Void )
-
Undocumented
Declaration
Swift
public func onError( handler: @escaping (_ rpc: DiscordRPC, _ nonce: String, _ eventError: EventError) -> Void )
-
Undocumented
Declaration
Swift
public func onEvent( handler: @escaping (_ rpc: DiscordRPC, _ eventType: EventType, _ event: Data) -> Void )