Yes, your usage is correct.
"A"/"An" are indefinite articles, which are used when the subject of the article is not specifically identifiable by the reader/listener.
My question was answered by a StackExchange user (as there are many StackExchange users)
"The" is the definite article, which is used the subject of the article is specifically identifiable by the reader/listener.
My question was answered by the ELL site on StackExchanges (as there is only one StackExchange user with that username; thank you to mcalex for the example)
Note that the sentence does not need to identify the article's subject itself. "The" can be also used because the subject is unique ("the year 2020 AD"), or the subject can be identified by a prior sentence.