This is a serverless Discord bot built with Discraft and Vercel! The bot uses OpenRouter's Kimi Dev AI model for chat functionality and includes GitHub repository browsing.
Note: This bot has been customized to use OpenRouter instead of Google AI.
Before you begin, make sure you have the following installed:
- Node.js (preferably version 18.x or higher)
- Vercel CLI
- Discraft CLI
First, create a new directory for your project and navigate to it:
mkdir my-discraft-project
cd my-discraft-projectNow, initialize a new Discraft project, choosing the Vercel template:
discraft init
? Select a template:
TypeScript
JavaScript
❯ Vercel + TypeScript + Google AIThis will create a new project with a structure something like this:
my-discraft-project/
├── commands/
│ ├── chat.ts (OpenRouter AI chat)
│ ├── ping.ts
│ └── repo.ts (GitHub repositories)
├── public/
│ └── index.html
├── scripts/
│ └── register.ts
├── utils/
│ ├── logger.ts
│ └── types.ts
├── .env.example
├── .gitignore
├── .vercelignore
├── index.ts
├── package.json
├── README.md
├── tsconfig.json
└── vercel.json
This bot uses OpenRouter's Kimi Dev AI model for enhanced chat interactions. You'll need to create an OpenRouter account and obtain an API key. Here's how to configure it:
- Obtain API Key: Visit OpenRouter and create an account to get an API key.
- Model Used: The bot uses
moonshotai/kimi-dev-72b:freewhich is a free model from OpenRouter. - Environment Variables: The project relies on several environment variables to function correctly. You will need to set these in your
.envfile locally and in the Vercel project settings.- Create a
.envfile in your project's root directory. - Add your Discord and OpenRouter credentials.
- Create a
Here's what you need in your .env file:
# You will need to add these secrets to the 'Environment Variables' section of your Vercel project
# https://vercel.com/docs/projects/environment-variables
# Discord Bot Configuration
# From `General Information > Public Key` | https://discord.com/developers/applications
DISCORD_PUBLIC_KEY=''
# From `General Information > App ID` | https://discord.com/developers/applications
DISCORD_APP_ID=''
# From `Bot > Token` | https://discord.com/developers/applications
DISCORD_TOKEN=''
# OpenRouter AI Configuration
# From your OpenRouter account | https://openrouter.ai/
OPENROUTER_API_KEY=''Important: Do not commit the .env file to your repository. It should be added to your .gitignore file. This is already done for you in the template.
- Create a Vercel Project: If you haven't already, create a new project in your Vercel dashboard.
- Set Environment Variables: In your Vercel project settings, go to "Environment Variables" and add all the variables you configured in your
.envfile (Discord and OpenRouter keys). You can find the project settings here. - Run a Discraft Build: In your project directory, run
npm run buildordiscraft vercel buildto create the API routes and files for your bot. - Deploy: You can deploy your bot to Vercel by running
npm run deployin your project directory.
- Create a Discord Application: Go to the Discord Developer Portal and create a new application.
- Add a Bot User: Add a bot user to your application.
- Invite the Bot: Use the 'OAuth2 > URL Generator' section to create an invite link and add your bot to a server. Select the
applications.commandsscope and send this link to a discord server you own so you can see your bot in action.
- Go to the Bot's Application Page: Go to the Discord Developer Portal and select your bot's application.
- Go to the General Information Tab.
- Set the Interactions Endpoint URL: In the Interactions Endpoint URL field, enter the URL of your bot's API endpoint. This should be the URL of your Vercel deployment, followed by
/api.
This bot comes with the following commands:
/ping: Responds with "Pong from Vercel!" to check if the bot is online./chat <prompt>: Uses OpenRouter's Kimi AI to respond to the given prompt./repo: Shows all GitHub repositories of Solar2004, sorted by stars and recent activity.
Need some assistance or want to see the bot in action? Join our Discord community! Discraft Support Discord
If you have ideas for the bot, or find any issues, you can create a pull request or issue on our github here: https://github.com/The-Best-Codes/discraft-js