Event Loop for a bot

Supposing I had a function in a script for a bot that gives me all the tweets a user has posted on X.com (sharkey, actually, but lets just say x), how would I make some kind of an event listener on a server that listens for mentions of the bot's account? I was thinking about making an infinite loop but that seems wildly inefficient.
Was this page helpful?