@@ -32,8 +32,8 @@ import { definePlugin } from 'zaileys'
3232export default definePlugin ({
3333 name: ' greet' ,
3434 description: ' Say hello' ,
35- command : async (c ) => {
36- await c .reply (' hi there 👋' )
35+ command : async (ctx ) => {
36+ await ctx .reply (' hi there 👋' )
3737 },
3838})
3939```
@@ -90,8 +90,8 @@ export default definePlugin({
9090 description: ' Say hello' ,
9191 cooldown: 3 ,
9292
93- command : async (c ) => {
94- await c .reply (' hi there 👋' )
93+ command : async (ctx ) => {
94+ await ctx .reply (' hi there 👋' )
9595 },
9696
9797 message : (m ) => {
@@ -142,7 +142,7 @@ import { definePlugin } from 'zaileys'
142142export default definePlugin ({
143143 name: ' my-plugin' ,
144144 description: ' What it does' ,
145- command : async (c ) => { /* handles !my-plugin */ },
145+ command : async (ctx ) => { /* handles !my-plugin */ },
146146 message : (m ) => { /* every inbound message */ },
147147})
148148```
@@ -152,7 +152,7 @@ export default definePlugin({
152152| Field | Type | Description |
153153| ----- | ---- | ----------- |
154154| ` name ` | ` string ` | Required. Identifies the plugin ** and** names the command ` command ` handles. |
155- | ` command ` | ` CommandHandler ` | Handles the command named after this plugin. Omit if the plugin only listens to events. |
155+ | ` command ` | ` (ctx, plugin) => void \| Promise<void> ` | Handles the command named after this plugin. 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
@@ -170,7 +170,7 @@ export default definePlugin({
170170 group: true ,
171171 admin: true ,
172172 cooldown: 3 ,
173- command : async (c ) => { /* ... */ },
173+ command : async (ctx ) => { /* ... */ },
174174})
175175```
176176
@@ -209,6 +209,25 @@ Available: `message` · `text` · `image` · `video` · `audio` · `document` ·
209209Each is typed from [ the event map] ( /events ) , so the payload needs no annotation. Listeners are
210210removed automatically when the plugin unloads.
211211
212+ ### Reaching the client
213+
214+ A command handler gets the client straight off its context:
215+
216+ ``` typescript
217+ command : async (ctx ) => {
218+ await ctx .client .group .removeMember (ctx .roomId ! , ctx .mentions )
219+ },
220+ ```
221+
222+ Event payloads are plain message contexts and carry no client, so every handler also receives the
223+ ** plugin context** as a second argument:
224+
225+ ``` typescript
226+ message : async (msg , plugin ) => {
227+ if (msg .text === ' ping' ) await plugin .client .send (msg .roomId ! ).text (' pong' )
228+ },
229+ ```
230+
212231## Going beyond the shorthands
213232
214233` setup(ctx) ` is still there for what the fields cannot express: registering ** several** commands
@@ -238,12 +257,12 @@ Supports aliases (pipe-separated) and multi-word commands. The command is automa
238257de-registered when the plugin unloads.
239258
240259``` typescript
241- ctx .command (' ping' , async (c ) => {
242- await c .reply (' pong' )
260+ ctx .command (' ping' , async (ctx ) => {
261+ await ctx .reply (' pong' )
243262})
244263
245- ctx .command (' help|h|?' , async (c ) => {
246- await c .reply (' Available: !ping, !help' )
264+ ctx .command (' help|h|?' , async (ctx ) => {
265+ await ctx .reply (' Available: !ping, !help' )
247266})
248267```
249268
@@ -254,7 +273,7 @@ defaults to the plugin's folder**, so `plugins/group/kick.ts` needs no `category
254273// plugins/group/kick.ts
255274ctx .command (
256275 { name: ' kick' , description: ' Remove a member' , group: true , admin: true },
257- async (c ) => { /* ... */ },
276+ async (ctx ) => { /* ... */ },
258277)
259278// registered with category: 'group'
260279```
@@ -335,8 +354,8 @@ export default definePlugin({
335354 const path = require (' node:path' )
336355 const config = require (path .join (ctx .pluginDir , ' config.json' ))
337356
338- ctx .command (' status' , async (c ) => {
339- await c .reply (` Mode: ${config .mode } ` )
357+ ctx .command (' status' , async (ctx ) => {
358+ await ctx .reply (` Mode: ${config .mode } ` )
340359 })
341360 },
342361})
0 commit comments