recovered from “Talmud Shabbat 30b”
Shabbat
שבת ל׳ ב — ד"ה ״וְשִׁבַּחְתִּי אֲנִי אֶת הַשִּׂמְחָה״ — שִׂמְחָה
Shabbat 30b:5
A man who spent every Sabbath studying died when the Angel of Death came to him because he never stopped studying, and the passage discusses various teachings about the value of human life and the book of Ecclesiastes.
״וְשִׁבַּחְתִּי אֲנִי אֶת הַשִּׂמְחָה״ — שִׂמְחָה שֶׁל מִצְוָה. ״וּלְשִׂמְחָה מַה זֹּה עוֹשָׂה״ — זוֹ שִׂמְחָה שֶׁאֵינָהּ שֶׁל מִצְוָה. לְלַמֶּדְךָ שֶׁאֵין שְׁכִינָה שׁוֹרָה לֹא מִתּוֹךְ עַצְבוּת וְלֹא מִתּוֹךְ עַצְלוּת וְלֹא מִתּוֹךְ שְׂחוֹק וְלֹא מִתּוֹךְ קַלּוּת רֹאשׁ וְלֹא מִתּוֹךְ שִׂיחָה וְלֹא מִתּוֹךְ דְּבָרִים בְּטֵלִים, אֶלָּא מִתּוֹךְ דְּבַר שִׂמְחָה שֶׁל מִצְוָה, שֶׁנֶּאֱמַר: ״וְעַתָּה קְחוּ לִי מְנַגֵּן וְהָיָה כְּנַגֵּן הַמְנַגֵּן וַתְּהִי עָלָיו יַד ה׳״. אָמַר רַב יְהוּדָה: וְכֵן לִדְבַר הֲלָכָה. אָמַר רָבָא: וְכֵן לַחֲלוֹם טוֹב.
Similarly, “So I commended mirth,” that is the joy of a mitzva. “And of mirth: What does it accomplish?” that is joy that is not the joy of a mitzva. The praise of joy mentioned here is to teach you that the Divine Presence rests upon an individual neither from an atmosphere of sadness, nor from an atmosphere of laziness, nor from an atmosphere of laughter, nor from an atmosphere of frivolity, nor from an atmosphere of idle conversation, nor from an atmosphere of idle chatter, but rather from an atmosphere imbued with the joy of a mitzva. As it was stated with regard to Elisha that after he became angry at the king of Israel, his prophetic spirit left him until he requested: “But now bring me a minstrel; and it came to pass, when the minstrel played, that the hand of the Lord came upon him” (II Kings 3:15). Rav Yehuda said: And, so too, one should be joyful before stating a matter of halakha. Rava said: And, so too, one should be joyful before going to sleep in order to have a good dream.