85 lines
1.8 KiB
Markdown
85 lines
1.8 KiB
Markdown
---
|
|
sidebar_position: 5
|
|
---
|
|
|
|
# Channels API
|
|
|
|
The channels API reads, selects, creates, renames, and removes server channels.
|
|
|
|
## Required Capabilities
|
|
|
|
| Method | Capability |
|
|
| --- | --- |
|
|
| `channels.list()` | `channels.read` |
|
|
| `channels.select(channelId)` | `channels.read` |
|
|
| `channels.addAudioChannel(request)` | `channels.manage` |
|
|
| `channels.addVideoChannel(request)` | `channels.manage` |
|
|
| `channels.rename(channelId, name)` | `channels.manage` |
|
|
| `channels.remove(channelId)` | `channels.manage` |
|
|
|
|
## List Channels
|
|
|
|
```js
|
|
export function activate(context) {
|
|
const channels = context.api.channels.list();
|
|
|
|
context.api.logger.info('Channels', channels.map((channel) => ({
|
|
id: channel.id,
|
|
name: channel.name,
|
|
type: channel.type
|
|
})));
|
|
}
|
|
```
|
|
|
|
Example channel list:
|
|
|
|
```json
|
|
[
|
|
{ "id": "general", "name": "general", "type": "text", "position": 0 },
|
|
{ "id": "support", "name": "support", "type": "text", "position": 1 },
|
|
{ "id": "lobby", "name": "Lobby", "type": "audio", "position": 10 }
|
|
]
|
|
```
|
|
|
|
## Select a Channel
|
|
|
|
```js
|
|
export function activate(context) {
|
|
context.api.channels.select('support');
|
|
}
|
|
```
|
|
|
|
## Add a Voice Channel
|
|
|
|
```js
|
|
export function activate(context) {
|
|
context.api.channels.addAudioChannel({
|
|
id: 'raid-voice',
|
|
name: 'Raid Voice',
|
|
position: 20
|
|
});
|
|
}
|
|
```
|
|
|
|
## Add a Video Channel Section
|
|
|
|
```js
|
|
export function activate(context) {
|
|
context.api.channels.addVideoChannel({
|
|
id: 'watch-party-video',
|
|
name: 'Watch Party',
|
|
position: 30
|
|
});
|
|
}
|
|
```
|
|
|
|
## Rename and Remove
|
|
|
|
```js
|
|
export function activate(context) {
|
|
context.api.channels.rename('raid-voice', 'Raid Voice - Tonight');
|
|
context.api.channels.remove('old-event-room');
|
|
}
|
|
```
|
|
|
|
Channel creation, rename, and removal should be user-confirmed because they change the shared server structure. |