Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/with-ai/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DISCORD_TOKEN="DISCORD_TOKEN"
GOOGLE_API_KEY="GOOGLE_API_KEY"
CLIPDROP_API_KEY="CLIPDROP_API_KEY"
40 changes: 40 additions & 0 deletions examples/with-ai/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# dependencies (bun install)
node_modules

# output
out
dist
*.tgz

# code coverage
coverage
*.lcov

# logs
logs
_.log
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# caches
.eslintcache
.cache
*.tsbuildinfo

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store

# CommandKit
.commandkit
dist

*.db*
21 changes: 21 additions & 0 deletions examples/with-ai/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Under Ctrl

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
100 changes: 100 additions & 0 deletions examples/with-ai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Agent 🤖

Agent is an advanced AI-powered Discord bot built with [CommandKit](https://commandkit.dev/) that leverages natural language processing to provide an intuitive and powerful interaction experience. Built with modern technologies, it offers a seamless way to manage Discord servers and engage with communities through various features.

## ✨ Features

- **Natural Language Commands**: Interact with the bot using everyday language
- **Channel Management**: Create and manage Discord channels effortlessly
- **Interactive Polls**: Create and manage polls with natural language inputs
- **AI Image Generation**: Generate images from text descriptions using Clipdrop API
- **Smart Chatbot**: Engage in natural conversations with context awareness
- **Google AI Integration**: Leverage Google's AI capabilities for enhanced features

> [!NOTE]
> This repository is just a simple example of what can be built with Agent. The actual implementation may vary based on your specific needs and requirements.

> Did you know that this project was vibe coded? 🤖 You can do that yourself by utilizing https://commandkit.dev/llms.txt in your code editor such as Cursor.

## 🚀 Getting Started

### Prerequisites

- [Node.js](https://nodejs.org/) (v22 or higher)
- A Discord bot token
- Google API key
- Clipdrop API key

### Installation

1. Clone the repository:

```bash
git clone https://github.com/underctrl-io/agent.git
cd agent
```

2. Install dependencies:

```bash
npm install
```

3. Configure environment variables:
Create a `.env` file in the root directory with the following variables:

```env
DISCORD_TOKEN="your_discord_token"
GOOGLE_API_KEY="your_google_api_key"
CLIPDROP_API_KEY="your_clipdrop_api_key"
```

You can obtain the required API keys from:

- Discord Token: [Discord Developer Portal](https://discord.com/developers/applications)
- Google API Key: [Google AI Studio](https://aistudio.google.com/apikey)
- Clipdrop API Key: [Clipdrop API Documentation](https://clipdrop.co/apis/docs/text-to-image)

4. Start the bot:

```bash
npm run dev
```

## 🎯 Features Showcase

### Natural Language Poll Creation

Create polls using everyday language. The bot understands context and can handle follow-up questions naturally.

![Create poll with natural language](./assets/create-poll.png)
![Create poll with natural language](./assets/create-poll-2.png)

### AI Image Generation

Generate images from text descriptions using natural language prompts.

![Generate image with natural language](./assets/image-generation.png)

### Context-Aware Chatbot

Engage in natural conversations with the bot that maintains context and provides relevant responses.

![Chatbot](./assets/chatbot.png)

## 🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

## 🙏 Acknowledgments

- [Discord.js](https://discord.js.org/) for the Discord API wrapper
- [CommandKit](https://commandkit.dev/) for the Discord.js framework with AI capabilities
- [Google AI](https://ai.google/) for generative AI models
- [Clipdrop](https://clipdrop.co/) for image generation API
Binary file added examples/with-ai/assets/chatbot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/with-ai/assets/create-poll-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/with-ai/assets/create-poll.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/with-ai/assets/image-generation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/with-ai/commandkit-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference path="node_modules/commandkit-types/index.d.ts" />
7 changes: 7 additions & 0 deletions examples/with-ai/commandkit.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'commandkit/config';
import { ai } from '@commandkit/ai';
import { tasks } from '@commandkit/tasks';

export default defineConfig({
plugins: [ai(), tasks()],
});
27 changes: 27 additions & 0 deletions examples/with-ai/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "commandkit-with-ai",
"type": "module",
"private": true,
"version": "0.1.0",
"description": "AI powered Discord bot built with CommandKit",
"scripts": {
"dev": "commandkit dev",
"build": "commandkit build",
"start": "commandkit start"
},
"dependencies": {
"@ai-sdk/google": "^2.0.19",
"@commandkit/ai": "^1.2.0-rc.12",
"@commandkit/tasks": "^1.2.0-rc.12",
"@types/ms": "^2.1.0",
"commandkit": "^1.2.0-rc.12",
"discord.js": "^14.23.2",
"ms": "^2.1.3",
"weather-js": "^2.0.0"
},
"devDependencies": {
"@types/bun": "latest",
"@types/node": "^24.0.1",
"typescript": "^5.8.3"
}
}
27 changes: 27 additions & 0 deletions examples/with-ai/src/ai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { configureAI } from '@commandkit/ai';
import { createGoogleGenerativeAI } from '@ai-sdk/google';
import { generateImageTool } from './tools/generate-image';

const google = createGoogleGenerativeAI({
apiKey: process.env.GOOGLE_API_KEY,
});

const model = google.languageModel('gemini-2.0-flash');

configureAI({
async selectAiModel() {
return {
model,
tools: {
generateImage: generateImageTool,
},
};
},
messageFilter: async (commandkit, message) => {
return (
!message.author.bot &&
message.inGuild() &&
message.mentions.users.has(message.client.user.id)
);
},
});
7 changes: 7 additions & 0 deletions examples/with-ai/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Client } from 'discord.js';

const client = new Client({
intents: ['Guilds', 'GuildMembers', 'GuildMessages', 'MessageContent'],
});

export default client;
124 changes: 124 additions & 0 deletions examples/with-ai/src/app/commands/channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import type { CommandData, MessageCommand } from 'commandkit';
import type { AiCommand, AiConfig } from 'commandkit/ai';
import {
ChannelType,
GuildChannelCreateOptions,
PermissionsBitField,
OverwriteData,
} from 'discord.js';
import { z } from 'zod';

export const command: CommandData = {
name: 'channel',
description: 'Manage channels in the server',
};

const channelConfig = z.object({
name: z.string().trim().min(1).max(100).describe('The name of the channel'),
type: z.enum(['text', 'voice']).describe('The type of channel to create'),
topic: z.string().trim().optional().describe('The topic for text channels'),
user_limit: z
.number()
.int()
.min(0)
.max(99)
.optional()
.describe('User limit for voice channels'),
nsfw: z
.boolean()
.optional()
.default(false)
.describe('Whether the channel is NSFW'),
private: z
.boolean()
.optional()
.default(false)
.describe('Whether the channel is private'),
parent: z
.string()
.optional()
.describe('The ID of the category to create the channel in'),
});

export const aiConfig = {
inputSchema: z.object({
channels: z
.array(channelConfig)
.min(1)
.max(5)
.describe('Array of channels to create'),
}),
} satisfies AiConfig;

export const message: MessageCommand = async (ctx) => {
await ctx.message.reply('This command can only be used via AI');
};

export const ai: AiCommand<typeof aiConfig> = async (ctx) => {
if (!ctx.message.inGuild()) {
return {
error: 'Channel management can only be used in a server',
};
}

const hasPermission = ctx.message.channel
.permissionsFor(ctx.message.client.user!)
?.has([
PermissionsBitField.Flags.ManageChannels,
PermissionsBitField.Flags.ViewChannel,
]);

if (!hasPermission) {
return {
error: 'Bot does not have the required permissions to manage channels',
};
}

const { channels } = ctx.ai.params;
const createdChannels = [];

for (const channel of channels) {
try {
const permissionOverwrites: OverwriteData[] = channel.private
? [
{
id: ctx.message.guild.id,
deny: [PermissionsBitField.Flags.ViewChannel],
},
{
id: ctx.message.author.id,
allow: [PermissionsBitField.Flags.ViewChannel],
},
]
: [];

const channelOptions: GuildChannelCreateOptions = {
name: channel.name,
type:
channel.type === 'text'
? ChannelType.GuildText
: ChannelType.GuildVoice,
topic: channel.topic,
nsfw: channel.nsfw,
userLimit: channel.user_limit,
parent: channel.parent,
permissionOverwrites,
};

const newChannel =
await ctx.message.guild.channels.create(channelOptions);
createdChannels.push(newChannel);
} catch (err) {
const error = err as Error;
return {
error: `Failed to create channel ${channel.name}: ${error.message}`,
};
}
}

return {
content: `Successfully created ${
createdChannels.length
} channel(s): ${createdChannels.map((c) => c.toString()).join(', ')}`,
};
};
20 changes: 20 additions & 0 deletions examples/with-ai/src/app/commands/ping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { ChatInputCommand, MessageCommand, CommandData } from 'commandkit';

export const command: CommandData = {
name: 'ping',
description: "Ping the bot to check if it's online.",
};

export const chatInput: ChatInputCommand = async (ctx) => {
const latency = (ctx.client.ws.ping ?? -1).toString();
const response = `Pong! Latency: ${latency}ms`;

await ctx.interaction.reply(response);
};

export const message: MessageCommand = async (ctx) => {
const latency = (ctx.client.ws.ping ?? -1).toString();
const response = `Pong! Latency: ${latency}ms`;

await ctx.message.reply(response);
};
Loading