Skip to content

OnlyArchanos/Tsun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Megumin

Tsun Bot

It's not like I wanted you to host me or anything, baka!

Hmph! So you actually want to set me up? I guess I can explain it to you since you'd probably mess it up otherwise. Don't get the wrong idea! I'm only doing this so you don't break my code.

Listen closely, idiot, because I'm only going to say this once. You need to set up the Discord Bot and the Web Dashboard. Pay attention!


Megumin Smug

Table of Contents

Step 1: Getting the Boring Stuff

Ugh, fine! First you need Node.js v18 or higher and Git. If you don't have them, what are you even doing here? Go download them right now:

  • Node.js — Download the LTS version, not the experimental one. Don't be reckless!
  • Git — Just install it with default settings, you don't need to configure anything special.

Once you have those, open a terminal and clone my code. Don't make any typos!

git clone <your-repo-link>
cd tsun
npm install

Okay? Now my main bot has its packages. We still need the web dashboard packages too, so don't close that terminal!

cd web
npm install
cd ..

If you see errors about missing packages, you probably have the wrong Node.js version. Run node --version and make sure it says v18 or higher, you dummy.



Step 2: The Discord Portal (Pay Attention!)

I need a body to control, obviously! Go to the Discord Developer Portal and log in with your normal Discord account. You don't need a special "developer" account, idiot.

  1. Click New Application in the top right. Give me a decent name and agree to the terms.
  2. You'll be on the General Information page. See that Application ID? That's your DISCORD_CLIENT_ID. You'll need it later for the web dashboard, so don't forget it!
  3. Go to the OAuth2 tab on the left. Look for Client Secret and click Reset Secret. Copy it IMMEDIATELY! That's your DISCORD_CLIENT_SECRET. If you close the page without copying it, it's gone forever and you'll have to reset it again. Don't show this to anyone, dummy!
  4. Now, go to the Bot tab on the left.
  5. Scroll down to Privileged Gateway Intents. This is CRITICAL! You HAVE to turn on Presence Intent, Server Members Intent, AND Message Content Intent. If you forget the Message Content Intent, I won't be able to read any commands and I'll literally ignore everyone. Your fault! Make sure you click the green Save Changes button!
  6. Go up to the Token section, click Reset Token, and copy the long password. That's your DISCORD_TOKEN. DO NOT SHOW THIS TO ANYONE! Are you crazy? If someone steals it, they steal me! And if you accidentally push it to GitHub, Discord will destroy it instantly.
  7. Now, go into my folder, find .env.example, rename it to .env, and paste that token next to DISCORD_TOKEN=.

Inviting Me to Your Server

To invite me to your server, you need to generate a special link:

  1. Go back to OAuth2 > URL Generator.
  2. Check the bot box. (You can also check applications.commands if you ever want to add slash commands later, whatever).
  3. Once you check bot, a Bot Permissions menu appears below. Check Administrator. Don't be stingy! I need full permissions to manage roles and channels, or I'm going to crash.
  4. Scroll to the bottom and copy the generated link.
  5. Paste it in a new browser tab. A Discord screen will pop up asking where to add me.
  6. Open the "Add to Server" dropdown menu and select a server where you personally have "Manage Server" or "Administrator" rights (otherwise the server won't even show up, baka!).
  7. Click Continue, review the permissions, click Authorize, and do the little human verification CAPTCHA.

If my role isn't high enough in your server settings to assign prestige roles, I'll throw an error. So go into your Server Settings → Roles and drag my role to the very top, got it?!


Megumin Pout

Step 3: MongoDB Database (Don't Mess This Up!)

I need somewhere to store all the user balances, inventories, and stocks! We're using MongoDB Atlas because it's free. Listen closely, because if you mess up the connection string, I'm going to crash immediately.

  1. Go to MongoDB Atlas and sign up. You don't need a credit card, so don't complain.
  2. Create an organization/project, then click Build a Database.
  3. DO NOT pick a paid tier unless you're rich! Pick the M0 (Free) deployment type.
  4. Once it's created, you might see a Security Quickstart screen (or just go to Database Access on the left).
  5. Create a Database User with a username and password.
    • WARNING: Do NOT use special characters like @, :, /, or ? in your password! It will literally break the URL and I'll refuse to connect. Stick to normal letters and numbers, idiot! WRITE THE PASSWORD DOWN.
  6. Go to Network Access on the left. Click Add IP Address and choose Allow Access From Anywhere (0.0.0.0/0).
    • WARNING: If you click "Current IP Address", only your personal computer can connect. When you try to host me on a real server, I'll crash instantly because I'll be blocked. So just use 0.0.0.0/0!
  7. Now, go to Database on the left, click Connect next to your cluster, and choose Drivers (Node.js).
  8. Copy the connection string. It looks like: mongodb+srv://username:<password>@cluster0...mongodb.net/?retryWrites=true
  9. CRITICAL STEP: Before you paste it into your .env, you have to edit it yourself:
    • Replace <password> with your actual password. And DELETE the < and > brackets! I can't believe I have to tell you that.
    • ADD MY NAME! Look at the .net/ right before the ?. You MUST insert TsundereBot right there so it looks like .net/TsundereBot?retryWrites=.... If you don't do this, MongoDB will just name the database test and dump all my precious data in a trash folder!
  10. Paste the fixed string into your .env next to MONGO_URI=, and put the exact same string into web/.env.local next to MONGODB_URI=.


Step 4: Cloudinary (For Images)

If you want me to process user inventories and generate custom duel canvases without Discord yelling at me about file sizes, you need this. Don't skip it!

  1. Go to Cloudinary and sign up for a free account.
  2. Go to your Dashboard. Near the top, you'll see a section called Product Environment. Look for your Cloud Name. Copy it and put it in your .env as CLOUDINARY_CLOUD_NAME.
    • (Note: This is a random string, NOT your email address. Don't mess that up!)
  3. Now for the keys. They recently moved these, so pay attention! Click on Settings (the gear icon) or look for a button that says Go to API Keys.
  4. On the API Keys page, you'll see a default key pair.
  5. Copy the API Key (it's a string of numbers) and paste it as CLOUDINARY_API_KEY.
  6. Click the reveal icon next to the API Secret. Copy that long, messy string and paste it as CLOUDINARY_API_SECRET.
    • WARNING: This secret gives full control over my image storage. If you leak this, I'm going to be so mad at you! If you ever think someone stole it, go back to that page and click Revoke immediately!


Step 5: The Admin Control Panel (DON'T IGNORE THIS!)

You probably looked at SESSION_SECRET and DASHBOARD_PASSWORD in the .env file and thought you could just leave them blank, right? WRONG!

  1. SESSION_SECRET: I run my own internal web server in the background for an admin panel. This secret string encrypts your browser cookies. You HAVE to type a long random keyboard smash here (like qwertyuiopasdfghjklzxcvbnmqwerty). If you leave this blank, I will literally throw a fatal error and refuse to boot up. So don't even try it!
  2. DASHBOARD_PASSWORD: When you visit my internal admin panel, I'm obviously going to ask for a password. If you leave this blank in the .env, I'll assume it's unsafe and I will automatically reject ALL login attempts, locking you out of your own control panel! Pick a password and write it down!


Step 6: MyAnimeList API (For the Weeb Stuff)

Do you want me to be able to look up anime and manga for you? Then you have to set this up! It's technically optional, but if you leave MAL_CLIENT_ID blank, any anime commands will just throw errors.

  1. Go to your MyAnimeList API Config page. You have to log into your MAL account first, obviously.
  2. Click the big button that says Create ID (or "Create new application").
  3. It's going to ask you to fill out a boring form. Just put this:
    • App Name: Tsun Bot (or whatever you want to call me)
    • App Type: Select Hobbyist (or "Other") since you're not paying them!
    • Homepage URL: Just put http://localhost or a link to your GitHub. It literally doesn't matter for a private bot.
    • App Redirect URL: Also put http://localhost. I only need public data, so we don't actually need a real OAuth redirect, but MAL forces you to type something here anyway.
    • Description: Type whatever, like "A discord bot for my friends".
  4. Click Submit.
  5. You'll instantly see your new app listed. Copy the Client ID (you don't need the Client Secret for this).
  6. Paste that Client ID into your .env file right next to MAL_CLIENT_ID=.

Megumin Magic

Step 7: Setting up the Web Dashboard

You thought we were done? Hah! You still have to configure my web interface so you can see all the fancy stats and graphs!

  1. Go into the web folder.
  2. Copy .env.local.example and rename the copy to .env.local. Don't rename the original, keep the example file as a backup!
  3. Open .env.local and fill in every single line. Here is what each one does, since I know you'd just stare at it blankly otherwise:
    • MONGODB_URI: Put the EXACT same MongoDB connection string you built in Step 3 here. Yes, the same one with TsundereBot in it. This is how the website reads from the same database as the bot.
    • AUTH_SECRET: This is a long random string that NextAuth uses to sign and encrypt session cookies for people logging into the web dashboard. Just mash your keyboard for 30+ characters. It doesn't matter what it is as long as it's random and long!
    • DISCORD_CLIENT_ID: Go back to the Discord Developer Portal, click your application, go to General Information, and copy the Application ID. You already grabbed this in Step 2!
    • DISCORD_CLIENT_SECRET: Go to the OAuth2 tab on the Discord portal and copy your Client Secret from there. You already copied this in Step 2 as well. See, I told you to save it!
    • AUTH_URL: Set this to http://localhost:3000 for local development. Once you actually deploy the web dashboard to Vercel or wherever, change this to your real public URL!


Step 8: Final Config and Launch

We're almost done but don't get cocky! Before you start me up, there are two things left:

1. Create the Discord Roles (MANDATORY)

Open config.js in the main folder and look at the ROLES section. You need to go into your Discord Server Settings → Roles and manually create every single role listed there with the EXACT same spelling, including capitalization! I'm talking about:

  • Iron, Bronze, Silver, Gold, Platinum, Diamond, Master (prestige roles)
  • Duel Lord, Sugar Daddy, Sugar Mommy
  • Gambling, True Member, Basically Everyone, member
  • Your mod role and owner role (check config.js to see what they're named for your server)

If even ONE role is missing or spelled wrong, I'll crash or silently break. Your fault, not mine!

2. Set Your Owner ID (Optional but Recommended)

If you want access to owner-only admin commands, go to your .env file and fill in OWNER_ID with your personal Discord User ID. To get your user ID: open Discord, go to Settings → Advanced, and turn on Developer Mode. Then right-click your own name anywhere and click Copy User ID.

Now Launch!

Okay, FINALLY everything is ready. Open a terminal in the main folder and type:

npm start

To start the web dashboard at the same time, open a second terminal, navigate into the web folder, and type:

npm run dev

If the bot console says Database Connected! and Tsun is online, then... I guess you didn't completely mess it up. B-but don't think I'm impressed or anything! Hmph!



Quick Reference: All .env Variables

Fine, I'll make a cheat sheet for you since you'll obviously forget where everything goes. You're welcome.

Root .env file (main bot)

Variable Where to get it Required?
DISCORD_TOKEN Discord Developer Portal → Bot → Reset Token Yes
MONGO_URI MongoDB Atlas → Connect → Drivers Yes
CLOUDINARY_CLOUD_NAME Cloudinary Dashboard → Product Environment Yes
CLOUDINARY_API_KEY Cloudinary → Settings → API Keys Yes
CLOUDINARY_API_SECRET Cloudinary → Settings → API Keys (reveal) Yes
DASHBOARD_PASSWORD Make one up yourself Yes (or I lock you out)
SESSION_SECRET Keyboard smash 30+ chars Yes (or I crash)
OWNER_ID Discord → Settings → Advanced → Developer Mode → right-click yourself Optional
MAL_CLIENT_ID myanimelist.net/apiconfig → Create ID Optional

web/.env.local file (web dashboard)

Variable Where to get it Required?
MONGODB_URI Same connection string as MONGO_URI above Yes
AUTH_SECRET Keyboard smash 30+ chars Yes
DISCORD_CLIENT_ID Discord Developer Portal → General Information → Application ID Yes
DISCORD_CLIENT_SECRET Discord Developer Portal → OAuth2 → Client Secret Yes
AUTH_URL http://localhost:3000 for local, your domain for production Yes

About

No description, website, or topics provided.

Resources

License

Stars

6 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors