While we were traveling with the Messenger of Allah ﷺ at al-Arj, a poet appeared reciting his verses. The Messenger of Allah ﷺ said, "Seize the devil," or "Hold back the devil. For a man's belly to be filled with pus is better for him than to be filled with poetry."
بينا نحن نسير مع رسول الله ﷺ بالعرج إذ عرض شاعر ينشد، فقال رسول الله ﷺ: خذوا الشيطان، أو أمسكوا الشيطان لأن يمتلئ جوف رجل قيحا خير له من أن يمتلئ شعرا.
Muslim narrated it in the Poetry chapter (2259) from Qutayba bin Saeed Thaqafi, who said, Layth narrated to us, from Ibn Hadi, from Yuhanis, the freed slave of Musab bin Zubayr, from Abu Saeed Khudri, who related it.This hadith is specific to this particular man, who was perhaps reciting poetry about obscenities and falsehoods, and it applies to everyone who does that. But if the poetry is in praise of the Prophet ﷺ and in his defense, calling to the oneness of Allah and to Islam, and refuting disbelief and shirk, then it is good and desirable, as has come in the sahih hadiths.