Expose Discord posting to moderation loop

This commit is contained in:
Meta Vens 2026-05-04 21:05:56 +01:00
commit 9b7e2ccbf6
6 changed files with 94 additions and 8 deletions

View file

@ -30,6 +30,7 @@ export async function postDiscordMessage(
botToken: string,
channelId: string,
content: string,
replyToMessageId?: string,
): Promise<{ id: string }> {
const response = await fetch(`https://discord.com/api/v10/channels/${channelId}/messages`, {
method: "POST",
@ -39,6 +40,12 @@ export async function postDiscordMessage(
},
body: JSON.stringify({
content,
message_reference: replyToMessageId
? {
message_id: replyToMessageId,
fail_if_not_exists: false,
}
: undefined,
allowed_mentions: {
parse: [],
},

View file

@ -24,6 +24,12 @@ export const notifyOwnerInputSchema = {
message: z.string().min(1).max(1800),
};
export const postDiscordMessageInputSchema = {
channelId: z.string().min(1),
content: z.string().min(1).max(1800),
replyToMessageId: z.string().min(1).optional(),
};
export const searchSourcesInputSchema = {
query: z.string().min(1).max(240),
limit: z.number().int().min(1).max(MAX_RETRIEVAL_RESULT_LIMIT).optional(),
@ -57,6 +63,12 @@ export interface NotifyOwnerArgs {
message: string;
}
export interface PostDiscordMessageArgs {
channelId: string;
content: string;
replyToMessageId?: string;
}
export interface ListIndexedReposArgs {
[key: string]: never;
}

View file

@ -10,6 +10,7 @@ import {
type ListIndexedReposArgs,
type MessageContextArgs,
type NotifyOwnerArgs,
type PostDiscordMessageArgs,
type SearchHistoryArgs,
type SearchSourcesArgs,
type SourceContextArgs,
@ -18,6 +19,7 @@ import {
formatSourceResults,
messageContextInputSchema,
notifyOwnerInputSchema,
postDiscordMessageInputSchema,
renderJsonBlock,
searchHistoryInputSchema,
searchSourcesInputSchema,
@ -294,6 +296,66 @@ export function registerVoidbotTools(
},
);
server.registerTool(
"post_discord_message",
{
title: "Post Discord Message",
description:
"Post a message to a Discord channel or thread as Void. Use this for constructive proactive participation, moderation nudges, or replies when speaking in-channel would genuinely help. Set replyToMessageId to reply to a specific message; omit it for a fresh post.",
inputSchema: postDiscordMessageInputSchema,
annotations: {
readOnlyHint: false,
destructiveHint: false,
idempotentHint: false,
openWorldHint: true,
},
},
async (input: PostDiscordMessageArgs): Promise<CallToolResult> => {
const { channelId, content, replyToMessageId } = input;
if (!context.config.botToken) {
return {
content: [
{
type: "text",
text: "DISCORD_BOT_TOKEN is not configured, so Discord posting is unavailable.",
},
],
structuredContent: {
sent: false,
reason: "missing_bot_token",
channelId,
},
isError: true,
};
}
const posted = await postDiscordMessage(
context.config.botToken,
channelId,
content,
replyToMessageId,
);
return {
content: [
{
type: "text",
text: replyToMessageId
? `Posted a reply in Discord channel ${channelId} as message ${posted.id}.`
: `Posted a message in Discord channel ${channelId} as message ${posted.id}.`,
},
],
structuredContent: {
sent: true,
channelId,
messageId: posted.id,
replyToMessageId: replyToMessageId ?? null,
},
};
},
);
server.registerTool(
"notify_owner",
{