Regular Command

How to create custom regular commands.

The Regular Commands Can execute by anyone with !prefix, Same as the Admin Commands

Preview

cari.js
const { default: axios } = require("axios");

module.exports = async (message) => {
    try {
        const kataKunci = (message.body).split(' ')[1].trim();
        const resp = await axios.get(`https://id.wikipedia.org/api/rest_v1/page/summary/${kataKunci}`)
        const datas = resp.data.extract;
        const balasan = datas
            if(datas){
                return balasan;
            }else {
                return `Gagal Saat Mencari ${kataKunci}.`
            }
    } catch (error) {
        return 'error while !Cari something';
    }
}

In this example, you import any Libraries for execution the command properly as you want.

Usage

make sure you have any correction before execute the function you have.

addap.js
        const kataKunci = (message.body).split(' ')[1].trim();
        const resp = await axios.get(`https://id.wikipedia.org/api/rest_v1/page/summary/${kataKunci}`)
        const datas = resp.data.extract;
        const balasan = datas
            if(datas){
                return balasan;
            }else {
                return `Gagal Saat Mencari ${kataKunci}.`
            }

the return must be a string/plaintext

Required

  • Try Catch Method: use the try catch everytime you make a new commands.
  • message: params from whatsapp-web-js that carrying any chat that you can create exeption with that.