hjjkh code example
Example: hjjkh
import SwordRPC
/// Additional arguments:
/// handlerInterval: Int = 1000 (decides how fast to check discord for updates, 1000ms = 1s)
/// autoRegister: Bool = true (automatically registers your application to discord's url scheme (discord-appid://))
/// steamId: String? = nil (this is for steam games on these platforms)
let rpc = SwordRPC(appId: "123")
rpc.onConnect { rpc in
var presence = RichPresence()
presence.details = "Ranked | Mode: \(mode)"
presence.state = "In a Group"
presence.timestamps.start = Date()
presence.timestamps.end = Date() + 600 // 600s = 10m
presence.assets.largeImage = "map1"
presence.assets.largeText = "Map 1"
presence.assets.smallImage = "character1"
presence.assets.smallText = "Character 1"
presence.party.max = 5
presence.party.size = 3
presence.party.id = "partyId"
presence.secrets.match = "matchSecret"
presence.secrets.join = "joinSecret"
presence.secrets.joinRequest = "joinRequestSecret"
rpc.setPresence(presence)
}
rpc.onDisconnect { rpc, code, msg in
print("It appears we have disconnected from Discord")
}
rpc.onError { rpc, code, msg in
print("It appears we have discovered an error!")
}
rpc.onJoinGame { rpc, secret in
print("We have found us a join game secret!")
}
rpc.onSpectateGame { rpc, secret in
print("Our user wants to spectate!")
}
rpc.onJoinRequest { rpc, request, secret in
print("Some user wants to play with us!")
print(request.username)
print(request.avatar)
print(request.discriminator)
print(request.userId)
rpc.reply(to: request, with: .yes) // or .no or .ignore
}
rpc.connect()