SHARDWIRE
Guides

App Bridge

Connect the app-side client, subscribe to events, invoke built-in actions, and branch on typed results.

The app bridge is the consumer side of the system.

Base connection

import { connectBotBridge } from 'shardwire';

const app = connectBotBridge({
  url: 'ws://127.0.0.1:3001/shardwire',
  secret: process.env.SHARDWIRE_SECRET!,
  appName: 'moderation-worker',
});

Event subscriptions

app.on('messageCreate', ({ message }) => {
  if (!message.content?.includes('!ping')) return;
  void app.actions.sendMessage({
    channelId: message.channelId,
    content: 'pong',
  });
});

Action calls

Always treat actions as typed request/response calls with explicit failure handling.

const result = await app.actions.timeoutMember({
  guildId,
  userId,
  durationMs: 60_000,
});

if (!result.ok) {
  console.error(result.error.code, result.error.details);
}

Voice subscriptions and controls

app.on(
  'voiceStateUpdate',
  ({ state }) => {
    if (state.channelId !== 'voice-room-1') return;
    console.log('in target voice room:', state.userId);
  },
  { voiceChannelId: 'voice-room-1' },
);

const moved = await app.actions.moveMemberVoice({
  guildId,
  userId,
  channelId: 'voice-room-1',
});

if (!moved.ok) {
  console.error(moved.error.code, moved.error.message);
}

What belongs here

  • subscriptions
  • product workflows
  • dashboards and admin tooling
  • moderation policies
  • metrics/reporting hooks

What does not belong here is raw Discord runtime ownership. That stays on the bot side.

On this page