Always Reply

newEvent Function

The newEvent function is used to create handlers that respond to specific events in your bot. It allows you to define various event types and associate them with custom actions.

Importing the Function

const { newEvent } = require('mvk-project');

Start by importing the newEvent function from the mvk-project package.

Defining the alwaysReply Event

module.exports = newEvent({
  type: 'messageCreate',
  action: async (message) => {
    // Reply to all messages with "hello"
    message.reply('hello');
  }
});

In this example, we use newEvent to define a handler for the alwaysReply event type. The action function is executed for every message received, allowing you to customize the response according to your needs.

Explanation of the Code

  • Importing newEvent: We first import the newEvent function from the mvk-project package.

  • Defining the Event: We use newEvent to create a handler where the type is messageCreate. The action function is called for each message, allowing you to define how the bot should respond. In this case, the bot replies with "hello". You can customize this function to perform any action you need.

Example Code

const { newEvent } = require('mvk-project');

module.exports = newEvent({
  type: 'messageCreate',
  action: async (message) => {
    // Reply to all messages with "hello"
    message.reply('hello');
  }
});

Event Types

The newEvent function supports various event types. Here are some common ones:

Summary

The newEvent function helps set up handlers that trigger actions based on specific events. You can define custom events and associate them with actions by specifying the appropriate event type. Customize the action function to handle messages and other events in various ways according to your bot's requirements. As you continue through the documentation, you’ll find more detailed explanations and examples of different event types.

Last updated