1.9 KiB
1.9 KiB
sidebar_position
| sidebar_position |
|---|
| 4 |
Server API
The server API reads the active server, registers plugin-owned users, and updates server settings or permissions.
Required Capabilities
| Method | Capability |
|---|---|
server.getCurrent() |
server.read |
server.registerPluginUser(request) |
users.manage |
server.updatePermissions(permissions) |
server.manage |
server.updateSettings(settings) |
server.manage |
Read Current Server
export function activate(context) {
const server = context.api.server.getCurrent();
context.api.logger.info('Current server', {
id: server?.id,
name: server?.name,
topic: server?.topic,
isPrivate: server?.isPrivate
});
}
Register a Plugin User
Plugin users are useful for bot-style messages.
export function activate(context) {
const botUserId = context.api.server.registerPluginUser({
id: 'standup-helper-bot',
displayName: 'Standup Helper',
avatarUrl: 'https://cdn.example.com/metoyou/plugins/standup-helper.png'
});
context.api.messages.sendAsPluginUser({
pluginUserId: botUserId,
channelId: 'general',
content: 'Standup reminder: share yesterday, today, and blockers.'
});
}
Capabilities required: users.manage and messages.send.
Update Server Settings
export function activate(context) {
context.api.server.updateSettings({
name: 'Friday Game Night',
topic: 'Co-op games, voice chat, and clips',
description: 'A friendly server for Friday sessions.',
maxUsers: 64,
isPrivate: false
});
}
Update Permissions
export function activate(context) {
context.api.server.updatePermissions({
allowVoice: true,
allowVideo: true,
allowScreenShare: true
});
}
Only update settings or permissions as part of an explicit admin flow. Plugins should not silently rename servers or change access rules.