1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Welcome to Lake Valor!
    Catch, train, and evolve Pokémon while you explore our community. Make friends, and grow your collection.

    Login or Sign Up

How To: Create Custom Discord Commands!

Discussion in 'The Lounge' started by Sanctuary, Sep 10, 2016.

Thread Status:
Not open for further replies.
  1. Sanctuary

    Odd Egg (S)
    (Odd Egg (S))
    Level 2
    Joined:
    Sep 6, 2014
    Posts:
    2,032
    PokéPoints:
    ₽94.1
    Pre-Tutorial Note: This tutorial uses JavaScript in order to set up these custom commands, but if you don't know JavaScript, no worries! Just read on and follow the steps, and then read the FAQ to learn more about making other custom commands (other than the default /lenny command I'll be giving you).



    Man oh maaaan, I discovered something so awesome yesterday. If you're on at least a couple Discord servers, you probably know what a bot is and that it can do some pretty cool stuff. But there's also this thing called selfbots, or basically, you are (partially) a bot.
    It's a bit confusing at first, but let me give you an example:
    I'm having a conversation on a server, and I want to send a ( ͡° ͜ʖ ͡°) face, but going out of my way to search it, copy, and paste it can get annoying. This is where selfbots come in.
    With regular bots, if you were to type a bot command such as /lenny, for example, it would trigger the bot command and the bot would send a lenny face. However, with a selfbot, you can make it so that your account sends that message.

    Before I go any further, I would just like to let you guys know that there are certain rules when it comes to selfbots. Here there are, be sure to read them before reading any further:
    Source: https://eslachance.gitbooks.io/discord-js-bot-guide/content/samples/selfbots_are_awesome.html

    But enough of the introduction, let's get down to business.

    Setting Up The Bot
    Fortunately, it doesn't cost anything to set up a bot, you can just run it off your own computer if you want to. There are a few limitations with running it off your own computer vs a Virtual Private Server (VPS), but we'll get to that later.

    1) You're gonna need something called a "token" in order for your bot to be able to login to your account. To do so, go to the following page: https://discordapp.com/developers/applications/me

    2) Once you're on that page, you can either right click, click on Inspect Element, or press Ctrl + Shift + i on your keyboard. After that, click on the Console tab and enter the following piece of code in it:

    localStorage.token
    It should output a long string of letters and numbers. Copy the output result and paste it somewhere safe (Don't include the " marks at the end or beginning).

    3) NOTE: IT IS VITAL THAT YOU DO NOT SHARE THIS WITH ANYBODY. IF SOMEONE GETS A HOLD OF YOUR TOKEN, THEY CAN SEND MESSAGES AND PERFORM MALICIOUS ACTS UNDER YOUR ACCOUNT. KEEP THIS IS MIND AT ALL TIMES.

    4) Once you've saved your token somewhere safe, go ahead and create a new folder on your Desktop (or wherever you want) and name it "Discord Bot" (or anything else you want).
    5) After that, you'll need to download something called Node.js. You can do so by going to their website and clicking on the v6.5.0 Current button. 6.5.0 may not be the latest version by the time you read this tutorial, but that's alright, just download whatever the latest version is. Downloading the 4.x series won't work though.
    Once you're finished downloading and installing, move on to the next step.

    5.1) If you don't already have a code editor (Notepad++, Sublime Text, Atom, etc.), it is recommended that you get one. Of course, it's not required, you can use the default Notepad program, but it's a mess to do it that way.
    Here are some links for code editing programs I've used in the past and recommend:
    I currently use Atom and love it, but I only recently stopped using Notepad++ after 4 years, and I can say that both are great programs. Haven't used Sublime Text much so I can't speak there.

    6) Go back to the "Discord Bot" folder you created. Once you're inside that folder, hold Shift and then right-click to open up the right-click menu. On there, you should be able to see an item listed as "Open command window here". Once you click that option, you should see something like this:
    [​IMG]

    7) Once you have that up, type npm and press enter. This will check if everything installed. It should look something like this:
    [​IMG]

    If it looks something like that, you're good to move on.

    8) Once done checking, you're gonna wanna type npm install discord.js and press enter.
    It'll take a short while to install, usually more or less around a minute, but you'll know when it's done installing.
    Note: If you receive some warnings at the end, such as "npm WARN {user} No description", feel free to ignore those, it should still have installed normally.

    After it's done, you can check if it successfully installed by typing npm list discord.js. If it returns something like -- [email protected], then it installed perfectly and you're almost ready to get your bot up and running!

    9) Open up your code editor and make a new file. Inside of that file, copy/paste this:
    const Discord = require("discord.js");
    const bot = new Discord.Client();

    bot.on("ready", () => {
    // Once the bot is ready, let us know by logging this message into the console
    console.log("Bot is connected!");
    });

    bot.on("message", (msg) => {
    // If the person who sent a message was NOT us, ignore it
    if (msg.author !== bot.user) { return; }

    // If the message we sent equals "/lenny", ...
    if (msg.content == "/lenny") {
    // Wait 0.1 seconds...
    setTimeout(() => {
    msg.edit("( ͡° ͜ʖ ͡°)"); // And then edit the message to the actual lenny face
    }, 100); // 100ms = 0.1s

    // The reason for waiting for 0.1 seconds *before* editing
    // is because sometimes Discord glitches and "unedits" the message, andthis can prevent that
    }
    });

    bot.login("YOUR_ACCOUNT_TOKEN_GOES_HERE");


    Remember that token from earlier? Grab it again and copy/paste it to the very bottom line of that code, where YOUR_ACCOUNT_TOKEN_GOES_HERE is.
    Save the file as selfbot.js, or anything you want to, really. Just make sure to remember it.

    10) Once you're done, go back to the command prompt and type node selfbot.js and wait a moment.
    If everything went well, the console will output "Bot is ready!". If so, you're good to go! If not, go back and re-read some of the steps and make sure you did everything accordingly.

    11) Create a new server for yourself and name it whatever you want. When you're in that server, type /lenny and watch the magic happen.
    [​IMG]

    You now have your own selfbot set up! Selfbots are amazing because you can add your own custom and secret commands that aren't available by Discord by default and are only accessible by you.

    F.A.Q.
    But Sanc, I don't know how to code, let alone code in JavaScript! Is there a simple way to add custom commands?
    Unfortunately, there is not. HOWEVER! Since I'm a nice guy (and love JavaScript and Discord.js), I'll allow you guys to make requests!
    Simply fill out the form in the topic message above the quick reply editor and I'll whip up to code to use and send it to you either via post or PM! :)

    I know other languages but I don't know JavaScript - can I use a different language?
    Yep! There are other Discord API libraries out there for different languages. You can check them out by going to this link: https://discordapi.com/unofficial/libs.html
    However, do note that this tutorial won't apply to other language libraries.

    Where will these commands work?
    Anywhere and everywhere! As mentioned before, this bot is running under your account, so wherever you go, it follows.

    Can I use this on the LV Discord server?
    Yep! Feel free to use your custom commands on our server, for as long as they fit within our Discord Chat Rules and Global Forum Rules.
    Spamming is a big no-no, so please avoid spamming your own commands. If possible, keep them inside the #bot-channel as well.

    What are the downsides to running this on my computer as opposed to a Virtual Private Server (VPS)?
    Running it on your computer means that it relies your computer to be functional, connected to the internet (obviously), and have the command prompt window open at all times.
    With a VPS, your bot can be up and running 24/7, even with your computer on! So you can use your commands on your phone while in bed or away from home, for example. The only download is that most decent VPS' cost money. Fortunately, I have a solution for you!
    You can sign up via this referral link and get a free $10 to spend on a VPS, which goes up to 2 months worth! Digital Ocean is the VPS service I use, and it is also the VPS service we used on the old Lake Valor Showdown server, so I would highly recommend it due to its ease of use, reliability, and cheap prices.
    You can also, of course, Google it yourself to see if you can find a free VPS out there, I'm pretty sure there's a few out there.



    If you have any other questions, run into any errors, or need any help with anything from this tutorial, feel free to ask me via a post, PM on here, or DM on Discord! I'll help you to the best of my ability to set up the bot. :)
    Hope you guys enjoy!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Thread Status:
Not open for further replies.

Share This Page