How do I check if a user executed a command? I would like to separate normal text and commands from eachother so I could give them a diffrent tag/type in my database.
Do I need to do something like this?:
bot.on('message',(msg)
message = msg.chat.text
check = message.slice(0,1)
if(check = '/'){
//command
} else {
//Normal text
}
);
The message type has an entity field to show if its a command. You can inspect the msg object for it.
The message type has an
entityfield to show if its a command. You can inspect themsgobject for it.
Do you have an example?
bot.on("message", (msg) => {
if (msg.entities && msg.entities.some((e) => e.type === "bot_command")) {
// here if the message has bot command
}
});
bot.on("message", (msg) => { if (msg.entities && msg.entities.some((e) => e.type === "bot_command")) { // here if the message has bot command } });
Why the msg.entities &&?
Because it msg object may not have it, if no entities are available. So, executing .some on undefined will report error.
Most helpful comment
Because it
msgobject may not have it, if no entities are available. So, executing.someon undefined will report error.