text
stringlengths
0
59.1k
## Treat Slack actions as tools
```ts
import { createTool } from "@voltagent/core";
import { VoltOpsClient } from "@voltagent/core";
import { z } from "zod";
const voltops = new VoltOpsClient({
publicKey: process.env.VOLTAGENT_PUBLIC_KEY!,
secretKey: process.env.VOLTAGENT_SECRET_KEY!,
});
export const postSlackUpdate = createTool({
name: "postSlackUpdate",
description: "Post a Slack message to a channel or DM.",
parameters: z.object({
text: z.string(),
channelId: z.string().optional(),
userName: z.string().optional(),
threadTs: z.string().optional(),
}),
execute: async ({ text, channelId, userName, threadTs }) => {
return await voltops.actions.slack.postMessage({
credential: { credentialId: process.env.SLACK_CREDENTIAL_ID! },
channelId: channelId ?? process.env.SLACK_DEFAULT_CHANNEL_ID!,
targetType: userName ? "user" : "conversation",
userName: userName ?? undefined,
text,
threadTs,
linkNames: true,
});
},
});
```
Agents can add the tool to their toolset to post progress updates, DM owners, or attach reactions as
they work through a task.
## Testing payloads in the console
- Open **Volt Console β†’ Actions β†’ Add Action** and pick the Slack action you want to test.
- Attach the Slack credential and choose defaults (channel/user modes, thread timestamp, etc.).
- Use the **Payload & Test** editor to try text, blocks, attachments, or reactions; successful runs
show the raw Slack response plus a copy-pasteable SDK snippet.
- Use console runs to capture the `messageTs` you need for delete/update/permalink or reaction
actions.
## Troubleshooting
- `channel_not_found` or `not_in_channel` usually means the bot is not invited to that channel or
lacks `chat:write` scope.
- DM and ephemeral messages require a `userId` or `userName`; ephemeral also needs the channel ID.
- `messageTs` values come from Slack responses (e.g., `chat.postMessage`); reuse them for delete,
update, permalink, and reaction actions.
- Blocks and attachments must be arrays; if you paste JSON strings, ensure they parse to arrays.
- Custom reactions should omit colons (use `eyes` or `name:emoji_id`).
- Check **Volt β†’ Actions β†’ Runs** to inspect payloads, metadata, retries, and provider errors.
<|endoftext|>
# source: VoltAgent__voltagent/website/actions-triggers-docs/actions/discord.md type: docs
# Discord Actions
Use Discord actions to announce deploys, coordinate incidents, or manage guild resources without
touching the Discord REST API. VoltOps supports bot-token actions for full control plus a lightweight
webhook action for simple notifications.
## Prerequisites
1. Discord application with a bot token. Invite the bot to the guild(s) you plan to use and grant
permissions for the actions you need (Send Messages, Manage Channels, Manage Roles, Add
Reactions, etc.).
2. (Optional) Discord incoming webhook URL if you only need to post messages via webhook.
3. A Volt project with API keys (`pk_…`, `sk_…`).
4. Discord credential inside Volt: **Settings β†’ Integrations β†’ Add Credential β†’ Discord**, then pick
**Bot Token** or **Webhook** and save. Volt generates a `cred_xxx` identifier.
5. (Recommended) Store defaults as environment variables:
```bash
DISCORD_CREDENTIAL_ID=cred_bot_xxx
DISCORD_WEBHOOK_CREDENTIAL_ID=cred_webhook_xxx
DISCORD_DEFAULT_GUILD_ID=123456789012345678
DISCORD_DEFAULT_CHANNEL_ID=123456789012345678
DISCORD_DEFAULT_THREAD_ID=987654321098765432
```
## Available actions
- `discord.sendMessage` / `discord.sendWebhookMessage`
- `discord.deleteMessage`, `discord.getMessage`, `discord.listMessages`
- `discord.reactToMessage`, `discord.removeReaction`
- `discord.createChannel`, `discord.updateChannel`, `discord.deleteChannel`
- `discord.getChannel`, `discord.listChannels`
- `discord.listMembers`
- `discord.addMemberRole`, `discord.removeMemberRole`
Message + channel actions require a bot token; webhook messages only require a webhook credential.
## Running Discord actions from code
```ts