@@ -32,7 +32,7 @@ import { definePlugin } from 'zaileys'
3232export default definePlugin ({
3333 name: ' greet' ,
3434 description: ' Say hello' ,
35- command : async (ctx ) => {
35+ message : async (ctx ) => {
3636 await ctx .reply (' hi there 👋' )
3737 },
3838})
@@ -90,12 +90,12 @@ export default definePlugin({
9090 description: ' Say hello' ,
9191 cooldown: 3 ,
9292
93- command : async (ctx ) => {
93+ message : async (ctx ) => {
9494 await ctx .reply (' hi there 👋' )
9595 },
9696
97- message : (m ) => {
98- console .log (' saw a message :' , m . text )
97+ image : (ctx ) => {
98+ console .log (' someone sent a picture :' , ctx . senderId )
9999 },
100100})
101101```
@@ -142,23 +142,23 @@ import { definePlugin } from 'zaileys'
142142export default definePlugin ({
143143 name: ' my-plugin' ,
144144 description: ' What it does' ,
145- command : async (ctx ) => { /* handles !my-plugin */ },
146- message : (m ) => { /* every inbound message */ },
145+ message : async (ctx ) => { /* handles !my-plugin */ },
146+ image : (ctx ) => { /* every inbound image */ },
147147})
148148```
149149
150150### The ` Plugin ` shape
151151
152152| Field | Type | Description |
153153| ----- | ---- | ----------- |
154- | ` name ` | ` string ` | Required. Identifies the plugin ** and** names the command ` command ` handles . |
155- | ` command ` | ` (ctx, plugin) => void \| Promise<void> ` | Handles the command named after this plugin . Omit if the plugin only listens to events. |
154+ | ` name ` | ` string ` | Required. Identifies the plugin ** and** names the command it handles. ` name: 'sticker' ` answers ` !sticker ` . |
155+ | ` message ` | ` (ctx, plugin) => void \| Promise<void> ` | Handles that command. Omit if the plugin only listens to events. |
156156| ` setup ` | ` (ctx) => void \| (() => void) \| Promise<…> ` | Optional escape hatch — see [ below] ( #going-beyond-the-shorthands ) . |
157157| ` onUnload ` | ` () => void \| Promise<void> ` | Optional cleanup, called on unload. |
158158
159159Beside those, a plugin carries ** every field a command spec carries** — ` aliases ` , ` description ` ,
160160` usage ` , ` category ` , ` hidden ` , ` metadata ` , and the guards ` group ` , ` private ` , ` admin ` , ` cooldown ` .
161- They describe the command that ` command ` handles. See
161+ They describe the command that ` message ` handles. See
162162[ Commands] ( /commands#describing-a-command ) for the full table.
163163
164164``` typescript
@@ -170,7 +170,7 @@ export default definePlugin({
170170 group: true ,
171171 admin: true ,
172172 cooldown: 3 ,
173- command : async (ctx ) => { /* ... */ },
173+ message : async (ctx ) => { /* ... */ },
174174})
175175```
176176
@@ -180,32 +180,37 @@ without saying so.
180180</Callout >
181181
182182<Callout type = " warning" >
183- Guards apply to ** ` command ` only** . An event method like ` message ` receives the raw stream — check
184- ` m .isGroup` yourself if you need to narrow it. This keeps ` admin ` from triggering a group-metadata
183+ Guards apply to ** ` message ` only** . An event method like ` image ` receives the raw stream — check
184+ ` ctx .isGroup` yourself if you need to narrow it. This keeps ` admin ` from triggering a group-metadata
185185lookup on every message that passes through your bot.
186186</Callout >
187187
188188## Event methods
189189
190- Every inbound event has a matching optional method. Hyphenated event names become camelCase, so
191- ` poll-vote ` is ` pollVote ` .
190+ Beside ` message ` , every inbound event has a matching optional method. Hyphenated event names become
191+ camelCase, so ` poll-vote ` is ` pollVote ` .
192192
193193``` typescript
194194export default definePlugin ({
195195 name: ' watcher' ,
196- message : (m ) => console .log (m .senderId , m .text ),
197- image : async (m ) => { await m .reply (' nice picture' ) },
198- pollVote : async (v ) => console .log (await v .options ()),
199- groupJoin : (e ) => console .log (' joined:' , e .participants .length ),
200- callIncoming : (c ) => console .log (' call from' , c .from ),
196+ text : (ctx ) => console .log (ctx .senderId , ctx .text ),
197+ image : async (ctx ) => { await ctx .reply (' nice picture' ) },
198+ pollVote : async (vote ) => console .log (await vote .options ()),
199+ groupJoin : (event ) => console .log (' joined:' , event .participants .length ),
200+ callIncoming : (call ) => console .log (' call from' , call .from ),
201201})
202202```
203203
204- Available: ` message ` · ` text ` · ` image ` · ` video ` · ` audio ` · ` document ` · ` sticker ` · ` reaction ` ·
204+ Available: ` text ` · ` image ` · ` video ` · ` audio ` · ` document ` · ` sticker ` · ` reaction ` ·
205205` edit ` · ` delete ` · ` pollVote ` · ` buttonClick ` · ` listSelect ` · ` mention ` · ` mentionAll ` ·
206206` groupUpdate ` · ` groupJoin ` · ` groupLeave ` · ` memberTag ` · ` callIncoming ` · ` callEnded ` ·
207207` historySync ` · ` limited ` · ` presence ` · ` newsletter ` .
208208
209+ <Callout type = " info" >
210+ There is no ` message ` event method — on a plugin that name is the ** command handler** . To watch every
211+ inbound message regardless of type, use ` setup(ctx) ` and ` ctx.on('message', …) ` .
212+ </Callout >
213+
209214Each is typed from [ the event map] ( /events ) , so the payload needs no annotation. Listeners are
210215removed automatically when the plugin unloads.
211216
@@ -214,7 +219,7 @@ removed automatically when the plugin unloads.
214219A command handler gets the client straight off its context:
215220
216221``` typescript
217- command : async (ctx ) => {
222+ message : async (ctx ) => {
218223 await ctx .client .group .removeMember (ctx .roomId ! , ctx .mentions )
219224},
220225```
@@ -223,8 +228,8 @@ Event payloads are plain message contexts and carry no client, so every handler
223228** plugin context** as a second argument:
224229
225230``` typescript
226- message : async (msg , plugin ) => {
227- if ( msg . text === ' ping ' ) await plugin .client .send (msg .roomId ! ).text (' pong ' )
231+ image : async (ctx , plugin ) => {
232+ await plugin .client .send (ctx .roomId ! ).text (' gambar diterima ' )
228233},
229234```
230235
0 commit comments