Skip to content

Create Custom Listener

AstroX10 edited this page Dec 28, 2024 · 1 revision

Custom Listeners

What are listeners?

These event handlers manage Xstro's operations while the client is active. They efficiently handle various tasks without causing lag or slowing down the bot's performance. Xstro executes all events using Promise-based operations, ensuring each task runs seamlessly without introducing latency or waiting for other tasks to complete. This approach optimizes execution and maintains smooth bot functionality.

How to create my own listener for my events.

  1. Navigate to the bot folder in the root directory.

    • Create a new file, e.g., foo.js, and add the following code:
    export async function Foo(msg) {
        if (msg.isGroup) return msg.send('Hey, this is a group, wow!');
    }
  2. Go to the lib folder and open the events.js file.

    • Scroll down to find the upserts function.
    • Inside this function, locate the tasks.push() block.
    • Import the Foo function and include it in the tasks.push() block.
  3. Run your bot.

    • When the bot receives a message in a group, it will always send a response saying, "Hey, this is a group, wow!"