fonzi2
TypeScript icon, indicating that this package has built-in type declarations

1.4.1 • Public • Published

Fonzi2 - Discord Bot Framework

Discord server package version npm downloads Tests status

Fonzi2 is an incredibly simple and fast Discord bot framework focused on a better dev experience, built using TypeScript and Discord.js. It provides a structured architecture with automatic command registration, event handling, and OAuth2 server-side functionality.

Table of Contents

Introduction

Developing a robust and scalable Discord bot can be a daunting task, especially for beginners. Fonzi2 simplifies this process by providing a structured framework that takes care of the essential boilerplate code and common discord bot functionalities.

Features

  • Structured bot architecture with automatic command registration and event handling
  • TypeScript support for type safety and code maintainability
  • Cookie-session management for secure user sessions
  • OAuth2 server-side functionality for user authentication and authorization
  • Lightweight and extensible framework to adapt to various bot requirements
  • Centralized on Discord API

Getting Started

The package has been created and tested with Node.js Version 18 and 20.
pnpm >= 8.14 was used as the package manager
I reccomend using nvm (Node Version Manager).

Installation

npm install fonzi2 discord.js 

Other packages you should install

  • for customizing the SSR
     npm install express ejs cookie-session

Required steps

  1. Create a new application in the Discord Developer Portal.

  2. Obtain the bot token from the Bot tab of your newly created application.

  3. [Invite link] Generate an OAuth2 URL using the OAuth2 URL Generator in the Discord Developer Portal. Select the bot scope and the permissions you need to generate the bot invite link.

  4. [ServerSide OAuth2] Generate an OAuth2 URL using the OAuth2 URL Generator in the Discord Developer Portal. Select the "identify" scope and http://localhost:<port>/login as your redirect uri for development and CHANGE response_type to token.

    • For production: you will need to create a new OAuth2 url using the hostname of your deployment (ex. https://fonzi2.railway.app/login as the redirect uri), remember to CHANGE response_type to token.

Contributing

I welcome contributions to the project. Feel free to open issues or submit pull requests with improvements or bug fixes.

Deployment

Dedicated Server (PM2)

You can host your bot on a dedicated server using the pm2 package.

  1. Set up Node.js and npm on your server.

  2. Install PM2:

    If you don't have PM2 installed on your server, install it globally:

    npm install pm2 -g
  3. Clone your bot repository onto the server:

    git clone https://github.com/your-username/your-bot.git
    cd fonzi2
  4. Install dependencies:

    npm install
  5. Configure .env

    TOKEN=your-bot-token
    LOG_WEBHOOK=optional-webhook-url
    INVITE_LINK=bot-invite-link
    # Production OAuth2 url
    OAUTH2_URL=your-oauth2-url
    OWNER_IDS=your-user-id,contributors-user-ids
  6. Build the project and start the process

    npm run build
    pm2 start npm --name "fonzi2" -- start
    • Replace "fonzi2" with your desired PM2 process name.
  7. Monitor and Manage:

    # see pm2 logs
    pm2 logs fonzi2
    
    # stop the bot
    pm2 stop fonzi2
    
    # restart the bot
    pm2 restart fonzi2
    
    # view process information
    pm2 show fonzi2

Serverless (Railway)

By far the simplest way to host a Discord bot for free*, this approach is excellent for small to medium-sized applications with minimal resource requirements, but theres also premium options for more demanding apps.

  1. Sign in to Railway with GitHub.

    • Click on "Create project" to create a new project.
    • Select "Deploy from GitHub repo" and select your bot repository.
  2. Setup env

    • DO NOT push the .env file to your repo as it contains sensible information about your bot that would become public, instead create Service Variables on railway, you can just copy and paste your existing .env, but make sure to change the necesarry variables to their production counterparts.
  3. There is no step 3, you are done!

    • Whenever you push to the default branch in your repo railway will fetch the changes and redeploy the bot, it goes without saying that the bot will stay online 24/7 without any external needs

Readme

Keywords

Package Sidebar

Install

npm i fonzi2

Weekly Downloads

144

Version

1.4.1

License

MIT

Unpacked Size

2.73 MB

Total Files

196

Last publish

Collaborators

  • ljs360d