While there are instances where and individuals who use text and discourse as basically synonymous terms, there is a difference in their definitions as regards agents (who and whom) and purpose fulfilled. In text, agents are not a critical factor: there may agents, there may not be. For example, in CERN press release text, there are none: information is being reported, that's all. In a novel's text, there are agents, such as Elizabeth and Darcy in Pride and Prejudice, who carry on a conversational discourse amongst themselves that the reader observes. The propose of text, therefore, is to relay or communicate information and may often be non-interactive, meaning the reader of the text is an observer.
While discourse is used in a nontechnical sense to mean conversational communication, linguistics, narratology and literary theory have developed a technical meaning to discourse. It is this meaning that confuses the issue of the difference between text and discourse. To start with, conversational discourse as between you and your friend or Elizabeth and Darcy is a behavioral event, called a recognizable speech event, that has individual purpose. Contrastingly, discourse in linguistics, narratology, and literary theory is a social event of multi-layered communication in a variety of media (verbal, textual, visual, audial) that has an interactive social purpose.
To study text, you study the written words that communicate some information: structure, theme, meaning, rhetorical devices, etc. To study discourse, you study who is communicating with whom through what medium and for what social purpose. Let’s use this answer as an example. To study or analyze the text, you will note the overall structure and (most importantly!) you will grasp the meaning of the content as it answers your question. To study or analyze the discourse, you will determine who is communicating with whom through what medium and for what social purpose.
Let's analyze discourse together. In this answer I am communicating with you through a textual medium--but not you alone. I am also communicating with the larger social group made up of anyone who reads this after you do--and the discourse goes two ways as you or others comment upon, makes notes about, talk about, etc. my side of the discourse. This answer builds an intricate social network of participants in a multiple-direction interactive discourse. What is the purpose of this discourse? Well, that is more complex; there may be many levels of purpose.
Of the many, the most obvious purpose is to answer your question and differentiate between text and discourse. Another purpose is for me to articulate ideas about concepts that are important to me. Another purpose is to respect your--and other readers--personal background and educational system while I do so. This is discourse: it has multiple interactive layers and it has multiple complex social purpose.
The same analysis can be applied to your conversation with your friend and to the text of Pride and Prejudice: you can find the multiple layers in various media that comprise the social event and the various purposes of discourse. In summary: Text is a behavioral non-interactive event restricted to your experience with understanding its characteristics and its meaning or information as its singular purpose. Discourse, in any medium, is a social interactive event with many layers of communication and many layers of purpose.