@tf2pickup-org/mumble-client

中文文档
0.15.2发布于 2026/11/02MITTypeScriptES Module构建来源已验证

A simple bot for managing mumble servers

原始使用文档
文档目录25 节
  1. Features
  2. Installation
  3. Quick start
  4. Examples
  5. Connect with a password and access tokens
  6. List all channels
  7. Find a channel
  8. Create and manage channels
  9. Move users between channels
  10. Mute/deafen yourself
  11. Register and manage users
  12. Text messages, certificate hashes and addresses
  13. Check channel permissions
  14. Listen to events
  15. Error handling
  16. API overview
  17. Client
  18. ChannelManager
  19. Channel
  20. UserManager
  21. User
  22. Permissions
  23. Events
  24. ClientOptions
  25. License

mumble-client

A simple mumble client for managing mumble servers

Latest release Test status MIT license

Features

  • Connect to any Mumble server over TLS
  • Manage channels: create, remove, link/unlink, fetch ACLs
  • Manage users: move, mute/deafen, register/deregister, rename
  • Send and receive private text messages; read certificate hashes and client IP addresses
  • Query channel permissions
  • Event-driven architecture with full TypeScript support
  • Automatic keep-alive pinging

Installation

npm i @tf2pickup-org/mumble-client

Quick start

import { Client } from '@tf2pickup-org/mumble-client';

const client = new Client({
  host: 'mumble.example.com',
  port: 64738,
  username: 'my-bot',
  rejectUnauthorized: false,
});

await client.connect();
console.log(`Connected! Welcome message: ${client.welcomeText}`);
console.log(`Logged in as ${client.self?.name}`);

// ... do work ...

client.disconnect();

Examples

Connect with a password and access tokens

const client = new Client({
  host: 'mumble.example.com',
  port: 64738,
  username: 'my-bot',
  password: 'server-password',
  tokens: ['token-for-acl-group'],
  clientName: 'my-awesome-bot',
  rejectUnauthorized: false,
});

await client.connect();

List all channels

import { type Channel } from '@tf2pickup-org/mumble-client';

function printChannel(channel: Channel, level = 0) {
  if (channel.name) {
    console.log(' '.repeat(level * 2) + channel.name);
  }

  for (const subChannel of channel.subChannels) {
    printChannel(subChannel, level + 1);
  }
}

printChannel(client.channels.root);

Find a channel

// by name
const lobby = client.channels.byName('Lobby');

// by path (from root)
const redTeam = client.channels.byPath('Match 1', 'RED');

// by custom predicate
const tempChannels = client.channels.findAll(ch => ch.temporary);

Create and manage channels

const root = client.channels.root;

// create a sub-channel under root
const matchChannel = await root.createSubChannel('Match 1');

// create team channels
const red = await matchChannel.createSubChannel('RED');
const blu = await matchChannel.createSubChannel('BLU');

// link two channels together
await red.link(blu);

// unlink them
await red.unlink(blu);

// remove a channel (and all its sub-channels)
await matchChannel.remove();

Move users between channels

const user = client.users.byName('PlayerOne');
const targetChannel = client.channels.byName('RED');

if (user && targetChannel) {
  await user.moveToChannel(targetChannel.id);
}

Mute/deafen yourself

// self-mute
await client.self.setSelfMute(true);

// self-deafen
await client.self.setSelfDeaf(true);

// unmute
await client.self.setSelfMute(false);

Register and manage users

// register the currently logged-in user
await client.self.register();

// fetch all registered users from the server
const registeredUsers = await client.fetchRegisteredUsers();
for (const user of registeredUsers) {
  console.log(`${user.userId}: ${user.name}`);
}

// rename a registered user (does not need to be online)
await client.renameRegisteredUser(userId, 'NewName');

// deregister a user (does not need to be online)
await client.deregisterUser(userId);

Text messages, certificate hashes and addresses

client.on('textMessage', async ({ sender, message, isPrivate }) => {
  if (sender && isPrivate) {
    await sender.sendMessage(`you said: ${message}`);
  }
});

// message everyone in a channel
await client.channels.byName('Lobby')?.sendMessage('hello');

// SHA1 hash of the user's certificate, sent for every user
console.log(user.hash);

// IP address; needs the Ban permission on the root channel
console.log(await user.fetchAddress());

Check channel permissions

const channel = client.channels.byName('Lobby');
if (channel) {
  const permissions = await channel.getPermissions();
  console.log('Can join:', permissions.canJoinChannel);
  console.log('Can create sub-channels:', permissions.canCreateChannel);
  console.log('Can remove:', permissions.canRemoveChannel);
  console.log('Can link:', permissions.canLinkChannel);
}

Listen to events

// user connected
client.on('userCreate', user => {
  console.log(`${user.name} connected`);
});

// user disconnected
client.on('userRemove', user => {
  console.log(`${user.name} disconnected`);
});

// user state changed (e.g. moved channel, muted, etc.)
client.on('userUpdate', (user, changes) => {
  if (changes.channelId) {
    const from = client.channels.byId(changes.channelId.previousValue);
    const to = client.channels.byId(changes.channelId.currentValue);
    console.log(`${user.name} moved from ${from?.name} to ${to?.name}`);
  }
});

// channel created
client.on('channelCreate', channel => {
  console.log(`Channel created: ${channel.name}`);
});

// channel removed
client.on('channelRemove', channel => {
  console.log(`Channel removed: ${channel.name}`);
});

// speaking state changes
client.on('speakingStateChange', ({ user, speaking }) => {
  console.log(`${user.name} ${speaking ? 'started' : 'stopped'} speaking`);
});

// disconnected from server
client.on('disconnect', payload => {
  console.log(`Disconnected: ${payload?.reason ?? 'unknown reason'}`);
});

Error handling

import {
  Client,
  ClientDisconnectedError,
  ConnectionRejectedError,
  PermissionDeniedError,
} from '@tf2pickup-org/mumble-client';

try {
  await client.connect();
} catch (error) {
  if (error instanceof ConnectionRejectedError) {
    console.error('Connection rejected by server');
  } else if (error instanceof ClientDisconnectedError) {
    // the server dropped the connection during the handshake,
    // or another connect() call superseded this one
    console.error('Connection lost');
  }
}

// background errors, e.g. a failed keep-alive ping; without a listener
// Node.js throws on an 'error' event
client.on('error', error => {
  console.error('Client error:', error);
});

try {
  await client.channels.root.createSubChannel('test');
} catch (error) {
  if (error instanceof PermissionDeniedError) {
    console.error('Insufficient permissions to create channel');
  }
}

API overview

Client

The main entry point. Connects to the server and provides access to channels, users, and events.

Property / MethodDescription
channelsChannelManager instance for finding channels
usersUserManager instance for finding users
selfThe currently logged-in User
sessionSession ID of the currently logged-in user
welcomeTextServer welcome message
serverVersionServer version info
serverConfigServer configuration (max users, message length, …)
socketThe underlying socket, for audio; undefined when disconnected
connect()Connect to the Mumble server; if already connected, disconnects first
disconnect()Disconnect from the server; does nothing when not connected
isConnected()Returns true if connected
fetchRegisteredUsers()Fetch all registered users
deregisterUser(userId)Deregister a user by ID
renameRegisteredUser(userId, name)Rename a registered user

ChannelManager

MethodDescription
rootThe root channel
byId(channelId)Find channel by ID
byName(name)Find channel by name
byPath(...path)Find channel by path segments
find(predicate)Find first matching channel
findAll(predicate)Find all matching channels

Channel

Property / MethodDescription
idChannel ID
nameChannel name
temporaryWhether the channel is temporary
usersUsers currently in this channel
subChannelsDirect sub-channels
linkedChannelsLinked channels
createSubChannel(name)Create a sub-channel
remove()Remove this channel
link(channel)Link with another channel
unlink(channel)Unlink from another channel
getPermissions()Fetch permissions for this channel
fetchAcl()Fetch the channel ACL
saveAcl(acl)Save the channel ACL

UserManager

MethodDescription
bySession(session)Find user by session ID
byName(name)Find user by name
findAll(predicate)Find all matching users

User

Property / MethodDescription
sessionSession ID
nameUsername
channelCurrent channel
channelIdCurrent channel ID
isRegisteredWhether the user is registered
mute / deaf / suppressServer mute/deaf/suppress state
selfMute / selfDeafSelf-mute/deaf state
moveToChannel(channelId)Move user to a channel
setSelfMute(mute)Set self-mute state
setSelfDeaf(deaf)Set self-deaf state
register()Register the user
deregister()Deregister the user
rename(name)Rename a registered user

Permissions

Property / MethodDescription
canJoinChannelCan join/enter the channel
canCreateChannelCan create sub-channels
canRemoveChannelCan remove channels
canLinkChannelCan link channels
canSelfRegisterCan self-register
canRegisterCan register other users

Events

EventPayloadDescription
connect—Client connected successfully
disconnect{ reason: string }?Client disconnected; emitted once per connection. reason is the server's (e.g. when kicked) or 'connection closed' when the server dropped the connection; no payload after disconnect() or a reconnect
errorunknownA background error, e.g. a failed keep-alive ping
channelCreateChannelA channel was created
channelUpdateChannel, ChannelChangesA channel was updated
channelRemoveChannelA channel was removed
userCreateUserA user connected
userUpdateUser, UserChangesA user's state changed
userRemoveUserA user disconnected
speakingStateChange{ user: User, speaking: boolean }A user started/stopped speaking

ClientOptions

Extends Node.js tls.ConnectionOptions.

OptionTypeDefaultDescription
hoststring—Server hostname
portnumber64738Server port
usernamestring—Username for authentication
passwordstring?—Server or user password
tokensstring[]?[]Access tokens for server ACL groups
clientNamestring?'simple mumble bot'Client name sent to the server
pingIntervalnumber?10000Keep-alive ping interval in ms

Since ClientOptions extends tls.ConnectionOptions, you can pass any TLS option such as rejectUnauthorized, cert, key, ca, etc.

License

MIT

版本与发布记录

@tf2pickup-org/mumble-client 共发布 24 个版本,首次发布于 2022/06/07;过去 12 个月发布了 8 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.15.2latest2026/11/02今天
0.15.12026/11/021 天前
0.15.02026/11/012 天前
0.14.02026/10/313 天前
0.13.12026/10/313 天前
0.13.02026/03/047 个月前

关于 @tf2pickup-org/mumble-client 的常见问题

@tf2pickup-org/mumble-client 是什么?

一个简单的机器人,用于管理mumble服务器

如何安装 @tf2pickup-org/mumble-client?

在项目目录运行 npm install @tf2pickup-org/mumble-client,或使用 pnpm add / yarn add / bun add。

@tf2pickup-org/mumble-client 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@tf2pickup-org/mumble-client 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@tf2pickup-org/mumble-client 可以商用吗?

@tf2pickup-org/mumble-client 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@tf2pickup-org/mumble-client 还在维护吗?

最新版本 0.15.2 发布于 2026/11/02(今天);至今共发布 24 个版本,其中过去 12 个月发布了 8 个;首次发布于 2022/06/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。