Skip to content

Commit 2d3d4b5

Browse files
committed
Add API docs for commands API
1 parent 3a7d241 commit 2d3d4b5

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

_api/commands.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
layout: documentation
3+
title: Commands
4+
description: The Commands API lets you create custom commands for users to run
5+
type: server
6+
---
7+
8+
The Commands API lets you create custom commands for users to run
9+
10+
## Methods
11+
12+
### `#add(command, function)`
13+
14+
Registers a new command for users on the lounge. `command` is what the users will type after `/`, and function is the command object. The `input` parameter on the command object will be run when the user inputs the command.
15+
16+
### `#runAsUser(command, chatId)`
17+
18+
Runs a command as the current user. Useful for amending messages sent, or for aliases for other commands. `command` is a string containing a standard IRC message, `chatId` is the channel or user to send the command to.
19+
20+
#### Example
21+
22+
```js
23+
const shrug = {
24+
input: function(client, target, command, args) {
25+
const messageWithShrug = args.join(" ").replace(/^\//, "") + " ¯\\_(ツ)_/¯";
26+
client.runAsUser(messageWithShrug, target.chan.id);
27+
}
28+
};
29+
30+
module.exports = {
31+
onServerStart(thelounge) {
32+
thelounge.Commands.add("shrug", shrug);
33+
}
34+
};
35+
```

0 commit comments

Comments
 (0)