WebFlake is currently in the process of upgrading fully to IPS 4.2.
We are aware that various functions may not be working correctly, or missing entirely.
Please use our Bug Tracker and Suggestions Tracker to help us with this transition.

You can dismiss this message at your discretion. Thanks!

Jump to content
Sign in to follow this  
Sanctuary

How To: Create Custom Discord Commands!

Recommended Posts

Sanctuary    291

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 furthe

Quote

I mentioned that userbots are not tolerated by Hammer & Chisel. Selfbots, however, are tolerated under a specific set of semi-offical rules under which they turn a blind eye:

  • A selfbot must not, under any circumstance, respond to other user's messages. This means it should not respond to commands, should not autoreply to certain keywords, etc. You must be the only one that can control it.
  • A selfbot must not, under any circumstance, do "invite scraping". This is the action of detecting server invites in chat, and automatically joining a server using that invite. That is akin to creating a virus, and it is not acceptable.
  • As selfbots run under your account they are subject to the same Terms of Service. That is to say, they should not spam, insult or demean others, post NSFW material, spread viruses or illegal material, etc. They have to follow the same rules that you follow.

IF, and only if you accept the above rules of selfbots, then you may proceed.

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:

3741473566068431a.png

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

3741473566390b923.png

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.

3741473568224c9d4.png

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

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.

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, 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.

Hope you guys enjoy!

Share this post


Link to post
Share on other sites
Pymous    0

I was actually looking at creating a Discord Bot not so long ago, thanks a lot !

Could you, by any luck, explain how to adapt this to a "standard bot" (AKA. get his token instead of mine) ? 

Thanks again :) 

Share this post


Link to post
Share on other sites
Sanctuary    291
On 9/28/2016 at 8:05 PM, Pymous said:

I was actually looking at creating a Discord Bot not so long ago, thanks a lot !

Could you, by any luck, explain how to adapt this to a "standard bot" (AKA. get his token instead of mine) ? 

Thanks again :) 

Whoops, sorry for the late reply. You've probably figured this out by now, but I'll leave this here for others who stumble upon this later on.

You create a bot and get its token by going to this page: https://discordapp.com/developers/applications/me
Once you're on that page, click on "Create Application", fill in the info, and submit it. Once you submit the info, click on this button:

374147555591871aa.png

Confirm the action and then you're done. After you click that, it'll look something like this:

37414755559583dd3.png

Click on the "click to reveal" button to grab your token, input it in the code, and you're done! :)

One important thing to note is that you can use most of the code in this tutorial, but you'll need to adjust some parts of it.
Here's an example code to get you started:

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 message that was sent is exactly equal to "!ping"...
	if (msg.content == "!ping") {
		// Send a message inside the same channel that say "Pong!"
    	msg.channel.sendMessage("Pong!");
    }

});

bot.login("YOUR_ACCOUNT_TOKEN_GOES_HERE");

Of course, that's just a very, very basic ping/pong setup you can use to test if your bot is working.
You can see the full reference of the documents by going to the Discord.js v9 docs page.

Good luck, have fun!

Share this post


Link to post
Share on other sites

Thank you! Been meaning to do something like this on my Discord server.

Share this post


Link to post
Share on other sites
What do you think? Remember the human.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×