discord-botREADME.md12 matches
1314- **Database Layer**: Uses Val.town's built-in SQLite database
15- **AI Integration**: Leverages Anthropic's Claude API for analysis
16- **Discord Integration**:
17- Bot token for fetching messages
18- Slash commands for user interactions
19- Webhook endpoint for Discord interactions
20- **API Endpoints**: Various endpoints for manual operations and automation
2122## Setup
31- `DISCORD_USER_ID`: Your Discord user ID
32- `SPOUSE_USER_ID`: Your partner's Discord user ID
33- `ANTHROPIC_API_KEY`: Your Anthropic API key
3435### Discord Bot Setup
54## Usage
5556### API Endpoints
5758- `GET /health`: Check if the service is running
59- `POST /api/interactions`: Discord interactions endpoint
60- `POST /api/fetch-dms`: Manually trigger DM fetching
61- `POST /api/process-links`: Manually trigger link processing
62- `POST /api/query`: Process a query about your messages
63- `POST /api/commands/search`: Endpoint for search commands
64- `POST /api/register-commands`: Register Discord slash commands
65- `GET /api/cron/fetch-dms`: Cron endpoint for fetching DMs
66- `GET /api/cron/process-links`: Cron endpoint for processing links
6768### Discord Commands
discord-bottypes.ts1 match
112}
113114// Claude API types
115export interface ClaudeOptions {
116model?: string;
discord-botindex.ts9 matches
69app.get("/shared/*", c => serveFile(c.req.path, import.meta.url));
7071// API endpoints
7273// Health check endpoint
8182// Discord interactions endpoint
83app.post("/api/interactions", async c => {
84return await handleDiscordInteractionRequest(c.req.raw);
85});
8687// Manual trigger for fetching DMs
88app.post("/api/fetch-dms", async c => {
89try {
90log("Manually triggering DM fetch...", "info");
106107// Manual trigger for processing links
108app.post("/api/process-links", async c => {
109try {
110log("Manually triggering link processing...", "info");
124125// Query endpoint
126app.post("/api/query", async c => {
127try {
128const body = await c.req.json();
151152// Discord command endpoints
153app.post("/api/commands/search", async c => {
154try {
155const body = await c.req.json();
214215// Register commands endpoint
216app.post("/api/register-commands", async c => {
217try {
218const applicationId = getEnv("DISCORD_CLIENT_ID");
297298// Expose cron endpoints via HTTP as well
299app.get("/api/cron/fetch-dms", async c => {
300const result = await cronFetchDMs();
301return c.json(result, result.success ? 200 : 500);
302});
303304app.get("/api/cron/process-links", async c => {
305const result = await cronProcessLinks();
306return c.json(result, result.success ? 200 : 500);
discord-botdiscord-commands.ts2 matches
47/**
48* Helper function to send command definitions to Discord
49* This would typically be called during setup using the Discord API
50*/
51export async function registerCommands(applicationId: string, token: string) {
52const endpoint = `https://discord.com/api/v10/applications/${applicationId}/commands`;
53
54try {
discord-botanthropic-service.ts4 matches
12export function initializeAnthropic() {
13if (!anthropic) {
14const apiKey = getEnv("ANTHROPIC_API_KEY");
15
16if (!apiKey) {
17throw new Error("ANTHROPIC_API_KEY environment variable is required");
18}
19
20anthropic = new Anthropic({
21apiKey,
22});
23
discord-botdiscord-client.ts6 matches
2import { saveDMMessages } from "./database.ts";
34// Discord API endpoints
5const API_BASE = "https://discord.com/api/v10";
67/**
8* Handle fetching DMs between users using Discord's API
9*/
10export class DiscordClient {
53async getDMChannel(userId: string) {
54try {
55const response = await fetch(`${API_BASE}/users/@me/channels`, {
56method: "POST",
57headers: {
88let keepFetching = true;
89
90// Fetch messages in batches of 100 (Discord API limit)
91while (keepFetching) {
92let url = `${API_BASE}/channels/${channelId}/messages?limit=100`;
93if (lastId) {
94url += `&before=${lastId}`;
discord-botval-town-deploy.js3 matches
26},
27{
28file: 'api-server.js',
29name: 'discordDMBotAPI',
30isPublic: true,
31description: 'HTTP API for Discord DM bot'
32}
33];
discord-botApp.tsx5 matches
111<tbody className="bg-white divide-y divide-gray-200">
112<tr>
113<td className="px-6 py-4 whitespace-nowrap font-mono text-sm">/api/interactions</td>
114<td className="px-6 py-4 whitespace-nowrap text-sm">POST</td>
115<td className="px-6 py-4 text-sm">Discord interactions endpoint</td>
116</tr>
117<tr>
118<td className="px-6 py-4 whitespace-nowrap font-mono text-sm">/api/fetch-dms</td>
119<td className="px-6 py-4 whitespace-nowrap text-sm">POST</td>
120<td className="px-6 py-4 text-sm">Manually trigger DM fetching</td>
121</tr>
122<tr>
123<td className="px-6 py-4 whitespace-nowrap font-mono text-sm">/api/process-links</td>
124<td className="px-6 py-4 whitespace-nowrap text-sm">POST</td>
125<td className="px-6 py-4 text-sm">Manually process links</td>
126</tr>
127<tr>
128<td className="px-6 py-4 whitespace-nowrap font-mono text-sm">/api/query</td>
129<td className="px-6 py-4 whitespace-nowrap text-sm">POST</td>
130<td className="px-6 py-4 text-sm">Query your conversation data</td>
131</tr>
132<tr>
133<td className="px-6 py-4 whitespace-nowrap font-mono text-sm">/api/register-commands</td>
134<td className="px-6 py-4 whitespace-nowrap text-sm">POST</td>
135<td className="px-6 py-4 text-sm">Register Discord slash commands</td>
discord-botDISCORD_BOT_SETUP.md6 matches
57```
5859## 7. Get OpenAI API Key
60611. Go to [OpenAI's website](https://platform.openai.com/)
622. Sign up or log in
633. Navigate to the API keys section
644. Create a new API key
655. Copy the key
666. Add it to your `.env` file:
67```
68OPENAI_API_KEY=your_openai_api_key_here
69```
70153## Next Steps
1541551. Customize the bot's responses by editing the API endpoints in `api-server.js`
1562. Add more categories for link classification in `database.js`
1573. Enhance the AI queries by modifying prompts in `query-service.js`
1584. Create a web interface that connects to your API endpoints
vt-discordindex.ts2 matches
12app.get("/frontend/**/*", c => serveFile(c.req.path, import.meta.url));
1314// Add your API routes here
15// app.get("/api/data", c => c.json({ hello: "world" }));
1617// Unwrap and rethrow Hono errors as the original error