Check Contains

checkContains

The checkContains function checks if the provided text contains any of the specified keywords. It returns true if at least one keyword is found in the text, and false otherwise.

Usage Examples

1. Event

Code:

const { alwaysReply, checkContains } = require('mvk-project');

module.exports = alwaysReply({
  action: async (message) => {
    const authorId = message.author.id;
    const result = checkContains({
      text: message.content,
      keywords: ['hi', 'hello']
    });
    if (result) {
      message.reply(`Hi <@${authorId}>!`);
    }
  }
});

2. Slash Command

Code:

const { newSlashCommand, slashOption, checkContains } = require('mvk-project');

module.exports = newSlashCommand({
  name: 'test-command',
  description: 'Test command',
  options: [
    {
      type: 'STRING',
      name: 'text',
      description: 'Text for check.',
      required: true
    }
  ],
  code: async function (interaction) {
    const authorId = interaction.user.id;
    const msg = slashOption(interaction, 'text');
    const result = checkContains({
      text: msg,
      keywords: ['hi', 'hello']
    });

    if (result) {
      await interaction.reply(`Hi <@${authorId}>!`);
    }
  }
});

3. Prefix Command

Code:

const { newCommand, checkContains } = require('mvk-project');

newCommand({
  name: 'test-command',
  code: async function (message) {
    const authorId = message.author.id;
    const result = checkContains({
      text: message.content,
      keywords: ['hi', 'hello']
    });
    if (result) {
      message.reply(`Hi <@${authorId}>!`);
    }
  }
});

If you’re not familiar with any of these functions, don’t worry— you’ll learn more about them later on!

Last updated