Nextjs Discord Bot... for free? Yes! we can actually create one using nextjs and host it for free in vercel! I made a template to make the process much easier!
This template wants you to just focus on making commands and we will do the rest. how you can easily create one.
import{SlashCommandBuilder}from"@discordjs/builders";import{executeCommand}from"@/types";// to add a command go to ./commands folder and create a new ts file// the command title/name should match the command.ts file for// ex. for tutorialhere command you should name the file tutorialhere.ts// Don't change register and execute variable namesexportconstregister=newSlashCommandBuilder().setName("tutorialhere").setDescription("description of your command");exportconstexecute:executeCommand=async (interaction)=>{// You have access to do interaction object// https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object// Do your bot logic here// You can even connect to a database// you should return a APIInteractionResponse// https://discord-api-types.dev/api/discord-api-types-v10#APIApplicationCommandInteractionreturn{type:4,data:{content:`Hello World! ${interaction.member?.user.username}`,},};};
thats it?! YEP simple as that, easy peasy
How it works π
A discord bot like this is possible because of the discord API, TLDR its just a normal http communication and our response just need to be a json format of type APIInteractionResponse and then the bot will respond!
Given all of the simplicity on how it works, there are still few things we need to take care of like, body parsing, interaction, registering the commands, verifying request, creating commands, typing system.
This boilerplate does it all for you so you can just focus on making commands and will take care of the underlying stuff so you can register and .
Limitations π£
As you might have guessed, this Discord bot cannot listen for messages or other events in the server and is likely restricted to handling slash commands only.