Docs Home | Client API | Objects and Enums
Register a handler with no filter:
client.on_message()(async function handle(message) {
console.log(message.content);
});Register a handler with a condition:
client.on_message(text)(async function handleText(message) {
console.log(message.text);
});Handler signature:
async function handler(message, client) {}Use on_command(name, extraCondition?):
client.on_command("ping")(async function ping(message) {
await message.reply("pong");
});With an extra filter:
client.on_command("ban", group)(async function ban(message) {
console.log(message.chat.id);
});client.on_error(async function logError(error, client) {
console.error(error);
});If you do not register an error handler, handler failures still propagate through the client flow.
Available lifecycle registrations:
on_connect(callback)on_disconnect(callback)on_initialize(callback)on_shutdown(callback)
Example:
client.on_connect(async function ready(current) {
console.log("connected as", current.user?.id);
});Exported message conditions:
textcontentgiftprivategroupchannel
Examples:
client.on_message(privateChat)(async function onlyPrivate(message) {
console.log(message.chat.id);
});client.on_message(all(group, text))(async function groupText(message) {
console.log(message.text);
});Exported helpers:
all(...conditions)any(...conditions)not(condition)create(predicate, label?)
Examples:
const onlyPrivateText = all(privateChat, text);
const textOrGift = any(text, gift);
const notChannel = not(channel);Every Condition also supports:
condition.and(other)condition.or(other)condition.not()condition.matches(client, event)
Example:
const privateText = privateChat.and(text);const fromMe = create(async function fromMe(client, message) {
return message.author.id === client.user?.id;
}, "fromMe");
client.on_message(all(text, fromMe))(async function selfText(message) {
console.log(message.text);
});Predicate signature:
async function predicate(client, event) {
return true;
}The package also exports command(name, prefix?, minArguments?, maxArguments?) as a condition builder.
Example:
const adminKick = command("kick", "/", 1, 1).and(group);
client.on_message(adminKick)(async function kick(message) {
console.log(message.text);
});- conditions are async-safe
- handlers receive wrapped
Messageobjects - updates with
rid === 0are ignored by the client before dispatch