More Premium Hugo Themes Premium Nextjs Themes

Nextjs Discord Bot

Discord bot template built with Next.js that runs 100% at the edge

Nextjs Discord Bot

Discord bot template built with Next.js that runs 100% at the edge

Author Avatar Theme by jzxhuang
Github Stars Github Stars: 80
Last Commit Last Commit: Jan 4, 2024 -
First Commit Created: Oct 26, 2023 -
default image

Overview

NextBot is a template for building and deploying a Discord bot with Next.js. It runs 100% in the edge runtime, resulting in lightning-fast responses and zero cold starts. It utilizes Discord interactions webhooks to receive and reply to commands. With NextBot, you can easily extend your bot by building an accompanying web app in the same repository.

Features

  • Runs at the edge: NextBot ensures lightning-fast responses and eliminates cold starts by running in the edge runtime.
  • Free & easy to deploy: Deploying NextBot to Vercel takes just seconds and incurs no cost. No need to host a separate server or VM to run your bot.
  • Easy to extend: Being built on Next.js, NextBot allows for easy integration and extension with an accompanying web app in the same repository.

Installation

  1. Clone the repository or use the “Use this template” button on GitHub to create your own repository based on the template.
  2. Install the dependencies by running yarn.
  3. Create a new Discord application and enable the Message Content intent in the Bot settings of your application.
  4. Copy the .env.local.example file in the root of the repository and create a new file named .env.local. Fill in the environmental variable values from your Discord app.
  5. Register the slash commands for your bot using the included script. Execute the command yarn register-commands to register the commands included in the demo bot. This script only needs to be run once, unless you add new commands.
  6. Set up a public HTTP address for Discord to send events to during local development. You can use an HTTP tunneling service like ngrok or Cloudflare Tunnel. For this guide, we will use ngrok. Start the Next.js application by running yarn dev and start an HTTP tunnel using ngrok http 3000. Set the Interactions Endpoint URL in the Discord app settings to <YOUR_PUBLIC_TUNNELED_NGROK_URL>/api/interactions.
  7. Verify the interactions endpoint URL by having Discord send a PING message to your bot. The bot should reply with a PONG. Once successful, your bot is ready to go.
  8. Add your bot to your Discord server using the generated invite link from Discord’s URL generator in the OAuth2 -> URL Generator section of your Discord app’s settings. Ensure that you select “bot + applications.commands” for scopes and “Send Messages + Use Slash Commands” for bot permissions.

Summary

NextBot is a Discord bot template built on Next.js, enabling lightning-fast responses and zero cold starts by running in the edge runtime. It eliminates the need for hosting a separate server or VM and allows for easy extension through an accompanying web app in the same repository. With easy installation steps and a seamless development experience, NextBot offers a convenient solution for building and deploying Discord bots.