There are a lot of Node.js Discord bots out there, but you can also build one with Next.js and host it for free on Vercel. An actually free Discord bot.
GitHub Repository · Live demo / invite the bot
How it works
Discord can send slash commands to a URL as plain HTTP requests, and the bot replies in the response. That's exactly what a Next.js route handler does, so there's no server to keep online.
The Boilerplate
It handles verifying requests, routing commands, registering them with Discord, and types. You just write commands:
export default defineCommand ( { data : new SlashCommandBuilder ( ) . setName ( "hello" ) . setDescription ( "Says hello" ) ,
execute : async ( interaction ) => ( { type : InteractionResponseType . ChannelMessageWithSource , data : { content : "Hello World!" } , } ) , } ) ;
Enter fullscreen mode
Exit fullscreen mode
Add it to src/bot/commands/index.ts , register from the home page, and it shows up in Discord. Since execute can be async, you can hit a database or an API too.…