How to code a Discord Bot step by step in JS

This guide will teach you step by step to make a Discord Bot that does some cool commands and stays online 24/7! This process is pretty easy for anyone to understand!

Before you start…

This guide sounds like a mouthful, but it’s really simple and allows anyone to create a bot! You don’t need to pay anything either since everything is totally free! You will also learn some JavaScript along the way! You will require:

  • A working Computer (This cannot be done on a mobile device)
  • A Verified Discord Account
  • Some basic JavaScript knowledge. (Take a look at some coding tutorials!)

If you have all of that, your all set! Let’s start by creating the bot!

Section I – Creating a Discord Bot

This first part is the easiest by far! First you must navigate to the discord website at https://discordapp.com/! Once your there, head to the developer portal by clicking Developers and then Developer Portal!

You’ll be brung to this Applications Page, click the new Application Button which should be in reach! After clicking it, put in a name! I’ll call this one Tutorial Bot for sake of the tutorial.

Once you’ve created it you’ll be brung to a whole new page! Note the app icon won’t actually show on the bot. Speaking of that, let’s create the bot! In the section on the left, click the Bot button! Now click the newly made “Add Bot” button! This’ll turn your application into a bot! You’ll see a lot of buttons!

You can see your bot already has a discord tag, at this point you can add an icon by clicking on that discord icon! Now that the bot is set up, keep this open as you will need two important things that you’ll need to invite the bot and to start it up in the code!

Section II – Invite the bot to a test server

Now that our bot is created, we can invite it! We’ll create a test server to test some stuff! Open discord in your browser or start up the discord app if you haven’t already, make a new server by clicking that plus button. If you don’t know how to get into the discord app in your browser just click the “Open” button on the discord website!

Now that you’ve made a new test server, it’s time to invite the bot! You’ll have to make a link yourself, heres a template:

https://discordapp.com/oauth2/authorize?client_id=CLIENT_ID&scope=bot&permissions=PERMISSIONS

Replace CLIENT_ID with the client id from your bot! Go back to “General Information” and click the copy button and paste that into the link. Then Replace PERMISSIONS with the permissions integer. You can find one back in the bot section and scroll down. I’d recommend checking Administrator so you can have access to all features, but if you want to just use some features then just click the ones you want. Now that your link is ready, press Enter!

Now just invite the bot like you would with any bot! Select the server and make it the server you just created or whatever server you plan to test in.

Click Authorize, do the Captcha, and then your bot has been added! Currently your bot is offline though, time to add some code!

Section III – Setup the coding enviorment

In this tutorial we will be using Glitch.com, it’s completely free and quite useful in creating bots! It also gives you 200MB to play around with data and there is friendly staff if you get stuck.

Head over to https://glitch.com/ and sign in! You have to use an existing account like Google, Facebook, Email or Github to sign in.

Click the New Project button, then you’ll want to click “hello-express” as we’ll be using the Node.js plugin. We can also add the packages we need later.

Now that you’ve created a project you should see something like this:

It looks like a lot, lets keep going.

There are a lot of unneeded files however, delete the client.js, style.css and index.html files as we do not need those. Then change the README to whatever you want. To delete a file, just click on it, then click the arrow and click delete.

Now in the “server.js” file, replace all the code with this:

const http = require('http');
const express = require('express');
const app = express();
var server = require('http').createServer(app);
app.get("/", (request, response) => {
  console.log(Date.now() + " Ping Received");
  response.sendStatus(200);
});
const listener = server.listen(process.env.PORT, function() {
  console.log('Your app is listening on port ' + listener.address().port);
});
setInterval(() => {
  http.get(`http://${process.env.PROJECT_DOMAIN}.glitch.me/`);
}, 280000);

It’s a little more efficient and sets up a port. We will have to install discord.js next. Go into package.json and click the Add Package button, search up discord.js and just click it. It will now install discord.js. I’d also open up Tools > Logs, so you can see whats going on. Now that discord.js is installed. We can start to add the code for this bot!

Section IV – Basic Bot Code

Now everything is installed. We can start by adding some bot code! Let’s start by putting in our secret token back in the developer portal. It’s in the bot section. Warning: Anyone who has this token has access to make your bot do different things! Don’t share it with anyone! Go into your .env file and replace the SECRET and MADEWITH code with TOKEN=

Then Copy the token from the developer portal and paste it right after the equal sign and no semicolons!

Go back into the server.js file add add these first few lines after all the current code.

const Discord = require('discord.js');
const client = new Discord.Client();

What this does is it gets the Discord library we installed a bit ago and creates a new client. Now we’ll need these two lines after the code you created:

client.on('message', message => {
  
});
client.on('ready', () => {
  
});

We have two client functions for when the client is on. One for when the bot sees a new message and the other for when the bot is ready. We’ll need one more line before we can do anything:

client.login(process.env.TOKEN);

The process.env.TOKEN is the token you put in the .env file a bit earlier. One cool thing about .env files is that no one can see inside it unless you have given them permission to edit your program! If you go back to the discord app in the server. The bot has been turned on! It does nothing at the moment but it’s better than nothing!

Let’s put a console.log in both functions

client.on('message', message => {
  console.log("\"" + message + "\" has been posted by " + message.author.id);
});
client.on('ready', () => {
  console.log(client.user.username + " is ready!");
});

So now every time someone posts a message, the bot will post it to logs and it will show the message and the creator. It will also post to logs when the bot is turned on! At this point your code might look something like this:

app.use(express.static('public'));
app.get('/', function(request, response) {
  response.sendFile(__dirname + '/views/index.html');
});
const listener = app.listen(process.env.PORT, function() {
  console.log('Your app is listening on port ' + listener.address().port);
});

const Discord = require('discord.js');
const client = new Discord.Client();

client.on('message', message => {
  console.log("\"" + message + "\" has been posted by " + message.author.username);
});
client.on('ready', () => {
  console.log(client.user.username + " is ready!");
});
client.login(process.env.TOKEN);

Try typing in some messages! Speaking of messages, let’s set up a basic command! How about a coin flipping command?

After the console.log line in the message function, let’s add an if statement to check for a prefix.

  var Message = message.toString();
  if(Message.startsWith("!")){
    var fullCmd = Message.slice(1);
    if(fullCmd.startsWith("flip")){
       coinFlipCommand(message);
    }
  }

First we check if the message starts with an !. If so it will create a new variable called fullCmd which is equal to message, without the first letter (Which in that case would be !). Then we check if the full command starts with "flip", and if so then we would call our flip function which doesn’t exist yet. So let’s create one!

Go before the message function but after the client variables and create a function called coinFlipCommand();

var coinFlipCommand = function(message){
    //command here
};

Then we’ll call the function back in that if statement

if(fullCmd.startsWith("flip")){
   coinFlipCommand(message);
}

You might have noticed that we have a parameter called message, this gets the message variable so we can send a message back in the function. To send a message back, go into the function and you would use:

message.channel.send();

But since it’s a coin flip command, we’ll need to decide if the coin lands on heads or tails.

  var coinside = Math.floor(Math.random()*2);
  if(coinside === 1){
    message.channel.send("Your coin landed on Tails!");
  }
  else{
    message.channel.send("Your coin landed on Heads!");
  }

Make sure those lines are in the function. If your project seems to have no errors. Go ahead and type in !flip! If the code was written correctly, the bot will either tell you Heads or Tails! If you look back in the function, Programming starts at 0, so that’s why we used 1 instead of 2 in our if statement! Let’s just set up one more thing and your basic discord bot is done!

Section V: Setting up the 24/7 uptime

Glitch projects will shut down if nothing is looking at it after 5 minutes, so we’ll need something free to ping the project so it stays up! Thankfully Uptimerobot exists! It’s useful, you can have up to 50 pingers without having to pay anything and Glitch suggests it themselves!

Head over to https://uptimerobot.com/ and create an account! Then log in with it and you’ll be brung to the dashboard! You’ll want to create something that’s called a Monitor. Click the “Add New Monitor” button! Click the Monitor Type dropdown and select “HTTP(s)”, put a nice name such as “Tutorial Bot Pinger”. For the url, go back to your Glitch project and click Show App, put it in a new window and then grab the URL when it’s loaded! Don’t worry about the error there, it’s just the HTML things that we deleted, and no one will actually see the page. It also won’t stop our bot unlike some errors which you may discover in the future.

Go back to the Uptimerobot on where your setting up your Monitor. Paste the URL on where the URL box is and leave the monitoring interval at 5 minutes. You’ll also want to check the email that you’ve attached so you can get emails if your Monitor is down. Don’t worry about the advanced settings. Click Done and wait just a minute to see if it works! Reload the page and if it says “Monitor Up”, then you’ve successfully set it up! Try closing the tab of your glitch project, wait a few minutes, play with it in discord, and see if it still works! The finished code is right here:

const http = require('http');
const express = require('express');
const app = express();
var server = require('http').createServer(app);
app.get("/", (request, response) => {
  console.log(Date.now() + " Ping Received");
  response.sendStatus(200);
});
const listener = server.listen(process.env.PORT, function() {
  console.log('Your app is listening on port ' + listener.address().port);
});
setInterval(() => {
  http.get(`http://${process.env.PROJECT_DOMAIN}.glitch.me/`);
}, 280000);

const Discord = require('discord.js');
const client = new Discord.Client();

var coinFlipCommand = function(message){
  var coinside = Math.floor(Math.random()*2);
  if(coinside === 1){
    message.channel.send("Your coin landed on Tails!");
  }
  else{
    message.channel.send("Your coin landed on Heads!");
  }
};

client.on('message', message => {
  console.log("\"" + message + "\" has been posted by " + message.author.username);
  var Message = message.toString();
  if(Message.startsWith("!")){
    var fullCmd = Message.slice(1);
    if(fullCmd.startsWith("flip")){
       coinFlipCommand(message);
    }
  }
});
client.on('ready', () => {
  console.log(client.user.username + " is ready!");
});
client.login(process.env.TOKEN);

Section VI: Grow your bot!

After your coin flip command, there is much more you can do! You could add more commands like a dice roll! Just copy and paste the if statement and make another function! You can look at the discord.js documentation!
In the future I’ll have more posts and video tutorials on how to make certain things for your bot, such as:

  • Make older commands work better
  • Turn your bot into a Music Bot
  • Make your bot store data
  • Bring your bot to Discord Bot List
  • Turn your bot into a leveling bot
  • Turn your bot into an RPG!

You can do many things yourself too! If you ever get stuck, Google is your best friend! You can even collab with others to make even better bots! Keep on coding and you’ll get better!

Thanks for checking out this tutorial! If you want you can check out my bot The Kepler Bot: The Kepler Bot | Discord Bots
Or Subscribe to my YouTube Channel: https://bit.ly/2KiMqZ5

That’s all for now!

What’s next for The Kepler Bot?

So you may now heard of The Kepler Bot, as you saw in the header of my website or on discordbots.org. If not, then it’s basically a bot that displays a mining area in a text environment, nothing too special but still really cool.

I’m quite proud of the popularity the bot has gotten, even if it doesn’t offer nearly as much as other bots do. You’re probably wondering what you’ll expect in the next few weeks of development. So sit back, relax, and read this post on what you can expect! Most of this might be small features, but they should make you still excited 😀

More Voting Prizes!

Even though getting 100 experience is great, I’d like to add quite a few more options. I might add some crate randomizer thing, which there would be four crates, Common, Uncommon, Rare and Legendary! Each crate will give out 5 possible prizes:

Common Crate – 40% chance

  • 50 Experience
  • 20 Gold + XP
  • 20 Iron + XP
  • 100 Stone
  • 30 Coal + XP

Uncommon Crate – 30% chance

  • 100 Experience
  • 25 Gold + XP
  • 30 Iron + XP
  • 10 Diamonds + XP
  • Go up a level

Rare Crate – 20% Chance

  • 250 Experience
  • 50 Gold + XP
  • 15 Diamonds + XP
  • 25 Diamonds + XP
  • Bonus Crate!

Legendary Crate – 10% Chance

  • Voting Pickaxe
  • 500 Experience
  • 1 Keplerium Ore + XP
  • 50 Diamonds + XP
  • Bonus Crate!

Those look like some nice crate selections. They’ll come real soon! Meanwhile keep voting at discordbots.org!

More Pickaxes

Even though the current pickaxes are nice, people may want more eventually as I saw someone get the diamond pickaxe almost in an instant, so I might add more pickaxes which will be harder to get.

  • Voting Pickaxe: 10% higher chances of gold, random ore than Diamond Pickaxe. You can win it from a Legendary Voting Crate, The chances are of getting one are actually 2%!
  • Donator Pickaxe: 15% higher chances of diamonds and random ore than the Diamond Pickaxe. You can get it by donating just one dollar to Kepler Teddy in the bot server or on my website! You also get twice the items!
  • Golden Pickaxe: Has Stone, Coal, Iron, Gold, Redstone and Lapis. You need 60 Gold to craft this pickaxe
  • Redstone Pickaxe: Has Stone, Coal, Iron, Gold, Redstone, Lapis and Diamonds. You will find 20% more Redstone than before. You will need 60 Redstone to craft this pickaxe
  • Lapis Pickaxe: Has Stone, Coal, Iron, Gold, Redstone, Lapis and Diamonds. You will find 20% more Lapis than before. You will need 60 Lapis to craft this pickaxe
  • Keplerium Pickaxe: Has basically everything. Known as the Ultimate Pickaxe in a way. You will require 6 Keplerium ore to craft it.

More Ores

Redstone, Lapis and Keplerium ore will now be available! To find Redstone and Lapis, you will either need a Gold, Redstone, Lapis or Keplerium Pickaxe!

Redstone Ore will have a 5% Find Rate at normal. Redstone will be used to speed up wait times for Regenerating Land or the Mining wait time. There will be those two upgrades which have three tiers. The first tier will cost 60 Redstone, The second will cost 120, and the final will cost 240.

  • No Tier: 180 Regenland Time, 5 Second Mining Cooldown
  • First Tier: 150 Regenland Time, 4 Second Mining Cooldown
  • Second Tier: 120 Regenland Time, 3 Second Mining Cooldown
  • Final Tier: 90 Regenland Time, 2 Second Mining Cooldown

Lapis Lazuli Ore will have a 3% Find Rate at normal. Lapis will be used to put enchantments on your pickaxe. Each enchantment has 3 tiers.

  • Fortune I: 1-2 per Ore
  • Fortune II: 1-3 per Ore
  • Fortune III: 2-4 per Ore (The Fortune enchantments can be combined with the donator picks, possibly providing 4 times the ores!)
  • Luck I: 5% higher chance of ores
  • Luck II: 10% higher chance of ores
  • Luck III: 15% higher chance of ores
  • XP Boost I: 25% More XP
  • XP Boost II: 50% More XP
  • XP Boost III: 100% More XP

Keplerium Ore will be extra rare at a only 1/500 chance of finding, the other way you can get it if you win it in a Legendary Crate! You’ll need 6 Keplerium Ore to make the Keplerium Pickaxe! 😀

Updates to current features

  • Default wait time to mine again will be 5 seconds
  • kb!multimine recreate will become kb!multimine regenland
  • A timer for when you last voted will be added at the bottom of the voting link when you do kb!vote, the timer will be the amount you have to wait until you can vote again.
  • Voting will give you a crate instead of 100 Experience.
  • Timers for regenerating land will be in minutes:seconds form instead of just seconds.
  • Data will be put in a database
  • The bot will now display the servers or miners. It will switch every now and then.
  • Pickaxes you own will be stored in an array. But the pick: variable will still be there, now known as the current pickaxe held.
  • There will be more than one arena. There will be arenas for different pickaxes. You can only go to the higher arenas if you have that pickaxe. But you can go to the lower tier arenas if you wish. Random ore will still be present.
  • Arenas will hold a max up to 10 pickaxes. It will start with 0 arenas until a user creates one. The arenas pickaxe type will be the creators.
  • kb!craft will become kb!craft <pickaxe>

More Commands!

Plenty more commands will be added as well! Here are all the commands in their specific categories!

Mining Commands:

kb!crate

This opens up the crates that you earn from voting! Read more about the crates quite a bit above.

kb!multimine <arena number>

This changes the arena you are in, if that arena doesn’t exist it will set it to the last arena.

kb!pickaxe <pickaxe>

This will switch your pickaxe to whatever is specified.

kb!upgrade

This will list the upgrades you can get and how much they cost.

kb!upgrade <number of enchantment>

This will buy the enchantment specified. Otherwise it will let you know if that enchantment doesn’t exist or you don’t have enough.

kb!donate

This will give you a link to the donate page.

Simple Commands

kb!tictactoe <opponent>

Starts a tictactoe game with the opponent specified. Acts like a normal tic tac toe game. If someone gets three in a row, they win! And if they have a mining user. They can win 20 XP! If it’s a draw, they both win 10 XP. You can’t start another tic tac toe game if you are currently in one. And both users have to confirm. If one doesn’t confirm, then the game doesn’t start. If one person takes more than 3 minutes. Then the other player only wins 10 XP. You will have to wait 5 minutes before you can start another tic tac toe game. And you’ll only win XP for the first five games.

kb!tictactoe <x-axis 1-3> <y-axis 1-3>

Puts a marker on the position specified. It goes to the next person.

kb!choose [item1] [item2] [item3] (etc.)

Chooses an item that is provided.

Other Commands

kb!servers

Tells you the amount of servers The Kepler Bot is on.

kb!users

Tells you the amount of users that have at least mined once.

That’s it for now! There will be more than on this page so stay tuned! 😀

The Adventures of Coding a Discord Bot

Me starting to write the basic code of my own mining discord bot!

Everyone uses Discord, right? No? Well, quite the majority do. So I’ve decided to turn my game into a Discord Bot! Creating a Discord Bot seemed like a good way to spread my coding influence, so I started creating one!

The Beginning

I wanted to start quickly and add a lot of stuff! I asked some people around Discord for tutorials and one pointed me towards Dapper Dino’s Bot Tutorials. I watched thru majority of them not understanding much, but my bot was set up and I could flip coins and roll dice.

That wasn’t enough so I followed a few more and added the music part to The Kepler Bot, then I wasn’t sure where to go from here. Until one day on my “Recreating Discord Miner into a Game” video, someone commented or DM’ed me, I can’t remember anymore. But they suggested that I turn my Miner Game back into a Discord Bot. Then I started to think…

The Completion

So I soon realized I was programming in Node.js, which was real similar to what I was used to programming in. Known as processingJS, which was linked to JavaScript, which is also what Node.js was also linked to, basically a lot of the stuff I knew could be used here too, which I thought was pretty neat. I soon figured my way thru Custom Emojis with some help from the mighty SpongeJr, who has also created a bot that acts like a role-play game!

I started using for loops, if statements, variables, math commands (well those were a little different but I still got used to them) and a lot more! Obviously rect(); or ellipse(); wouldn’t work as I was dealing with Discord.js and that was made completely of text and emojis, so I had to think a little creative if I wanted to create a mining scenario. Soon enough there were a lot of files in a lot of folders and it was hard to get around. But there was a working mining system, inventories, multiplayer mining, regeneration of land, and plenty more! But I soon realized that the basic code that Dapper Dino provided plus my code didn’t work too well, and things got easily confused like there were two help pages and classes everywhere which I currently don’t understand but I assume they are similar to functions (Which they probably are not :/), so I decided that it was time for a full rewrite of the entire code! Well I’d still have the data separate so there wouldn’t be a thousand lines to scroll thru if I wanted to add something new. The reason I wanted to rewrite the code is I was trying to access the Client (Known as bot in code) variable from the main file, but the other files were in a big folder. So it would be hard to access a file outside of the folder. I spent half an hour figuring it out but no luck.

The Rewrite

Thru the day I added the necessary basics like for when the bot turns on, the message function, and the commando classes. The rewrite was going great! Everything was working out! I created functions for each of the commands, everything would sync a lot better than before because they could access the same variables which saves a lot of code! I decided not to keep the music functions as I don’t see my bot as a music bot, more of a fun and helpful bot! All of the commands work fine and the command I got stuck on one point now will work much better!

And even today I’m still working on the rewrite and adding more commands! Like finishing up the top list command, adding support to check each others inventories, trading, bonuses and possibly moderation commands! I’ll put the link down here to the second and third videos when they are released, but for now, stay tuned!

Don’t forget to subscribe!: https://www.youtube.com/channel/UCocmE7xT6REn0p1kBEgmz2Q

Or follow my instagram!:
https://www.instagram.com/thekeplerteddy/

Thanks for reading! Or watching if you watched the videos!

New Years Plans!

Hello! Here are my plans for the start, middle and rest of the new year; 2019! I’ve got stuff for Khan Academy Community, YouTube and my apps! Starting with KACS!

Khan Academy Community:

First off, Monument Food II, lets get that out of the way! I will be working on it at least 15 minutes – 30 minutes every day if possible, I will also be doing 1 Hour Live streams every now and then where I code this game.

Next, I will be entering a lot of contests because I like contests, I won’t be too active on here, nor inactive, sorta in between for majority of the year, I will probably go hard cold inactive around summer as I’ll be spree coding my huge game in Unity.

That’s basically it, I’ll try and release some good games like MF II or Mesh Dance and some remakes though.

YouTube:

If you have followed my instagram, you probably have gotten a post on my January Youtube Schedule. And if you subscribed to my YouTube then you would’ve seen this video above all of this text! If not, shame on you, here are links for my Instagram and Youtube

Things I explained in my YouTube is that I won’t be doing too many ProcessingJS tutorials anymore but a variety of tutorials for different things! Also Minecraft and Gaming are returning to my channel so expect to see some Minecraft!

I also want to thank you for 300 views on my video, Discord Miner! That’s pretty awesome! Be sure to watch more of my videos and subscribe! That’s it for YouTube, onto the last big subject:

Apps and Unity:

Whew, here we go. First off, once I get this privacy policy working (which will appear on this website), City Dashz 1.2 will be out for iOS which currently is only for Android as of right now, a follow up bug-fixes update will arrive soon enough as City Dashz 1.2.1 and could be out Late January or earlier, which will fix glitches like not able to buy heads. Stick with bodies for now, it will still probably take you a while 😉

Soon enough in February or March, Tumbl3 will get some Music and a port to iOS! Very exciting! Also we have 30 downloads of City Dashz across all platforms! Tell your friends about the game! 😀

If you want more apps, you’re in luck, my next game: Impact, is another dodge game where you have to dodge balls, collect power-ups, buy characters, shaking terrors and more! It should be out around May! You can play the Khan version here: https://www.khanacademy.org/computer-programming/impact-103/6272456781529088

Another app I’ll be making which will arrive in September is Farmee! A simple game where you harvest crops, grow your farm, fish, sell, cook special food, sell that, cook even more special food, sell that. Yeah that’s basically it, just an awesome farm game!

I possibly might make one more app around December 2019 called Snowboarderz, which is a game where you snowboard, do challenges, championships and if I figure out, you just might be able to play with other players online :O

I might also be making a Online Multiplayer Shooter called Planetz.io (which I probably should reserve the domain, gulp! If someone takes it I’ll be quite mad :P) Where you collect resources to build weapons and fight other players with ship fights, lazer fights, galactical adventures and galactical disasters! With multiple modes, this game sure will be fun! This game will be Website based obviously, and will probably most likely make it in 2020, but you never know, I could finish it for Summer 2019! 😀

Lastly, this is the big game I’m working on, called Monument Food: Shards of Hope, which is an Adventure/RPG, you can do 2 player co-op, intense battles and awesome story! This will also be coming out of the end of the year, I will be sharing the progress of all stuff on my Instagram!

Whew, that’s a lot of stuff! Also, I might be building a PC! Hope you enjoyed this blog post and now you have the stuff to look forward too!

Recreating Mitcoin!

MITCOIN!

Ah, Mitcoin, what a peaceful way to make mon- AHHHH THE GRAPH IS GOING DOWN, NOO, I WANT IT TO GO UP! Oh, sorry! Mitcoin isn’t all peaceful when the graph doesn’t want to do what you want! Say, how about I recreate this fascinating bot! I’d recommend watching the video first!

So what is Mitcoin? Well its like Bitcoin, but if you don’t know what that is, its where you can buy a currency or trade it in for money, but there is the Mitcoin to money conversion, which is a graph that has its ups and downs!

We can create it pretty easily with the noise function, and making it change every second, an interesting thing is the graph doesn’t change if you restart it, it will change if you reload the page, I could’ve tried using randomSeed, I also could’ve added a save code! Maybe I’ll do that right now!

You can play the project right here!

What fun! Thanks for reading!

The Top List

Ah, the top list, the list which every single program is on, except that it is sorted by votes, which means 99.99% of them are at the bottom! Anyway, the top list has had many achievements, and a page is 30 programs each, the first page of the top list hasn’t changed, let’s observe.

We can see that the top three were created in 2013 then a lot of them were 2014 and 2015, there is only one 2016, 2012 and 2017 programs, there are no 2018 programs… One more thing I want to show you is the future of the top list! 😀

The Top list one year from now, unless another program gets banned!

What do you think? Obviously, the list couldn’t be more wrong, as even though the time-frame of the survey was 81 days, which the programs got this much in that time-frame:

Khanemon: 252
Doodle Jump: 242
Minecraft: 229
Mini Putt: 182
Escape Plan: 114
Duck Life: 102
Lava: 97
I saw Her Standing: 93
Mario: 88
Planes: 84
The Legend Of Zelda: 76
Terra Magma: 70
Infinity Hall: 67
Planetoid: 63
FIFA: 63
Cubix 2: 62
Cut The Rope: 60
Its a Big World: 58
Crate Ninja: 58
Doodle Dodge: 55
Transcolors: 55
MINI STIX: 53
iPhone: 48
sphere: 40
Flappy Bird: 33
Falling Pixel: 33
Zombie Invasion: 32
Redball: 31
HuskyCraft: 11
Flappy Bird (Kevin23): 11

As you can see, some programs have gotten more attention than the others, for example, three of the top five are on the top five themselves while the other two are programs that people really like because of the time spent on them, while on the bottom, Like simple programs or another version of a program that is placed higher on the list so this program doesn’t get as much recognition, as people are more likely to pick the first one. The top list has changed a lot, as programs go up and down, the farther down you go, the more difference there is over the days because the vote count of those ones are more similar

I think that is it! Be sure to subscribe to my blog and YouTube as I’ll start recreating some programs! 😀 

Recreating Discord Miner!

Hello! Welcome to Keplerteddy! And here is a post about my latest video, “Creating Discord Miner with code!” As you probably saw, it was mainly time lapse 😛 But there is more to it than you think! Get ready for some bonus content!

The start of mining, wooden pickaxes and according to code, graphics.

What I did add: Wooden, Stone, Iron, Gold, Diamond Pickaxes. Digging with different speeds. Levelling, Material Count.

What I added but never used: Material Graphics.

What I didn’t add: Redstone, Lapis, Emeralds, More Pickaxes, Bonuses, Enchantments, Long Term Saving, Trading, Money!

That’s all I’ve done on the game, I spent 1½ hours making this, and the graphics were made from 24 Hour Minecraft, saving me at least 15 minutes. Obviously, you probably want to try out the project for yourself! Just click this link to go to the Miner. You just hold to mine, pretty simple concept, let’s go thru the code to get a better understanding! Those 418 lines of code are just far too confusing!

Alright, the first few lines of code are mainly graphics, I store the information in string arrays:

{ //STONE
    d: [
        "001220",
        "011110",
        "020020",
        "002111",
        "111200",
        "001010",
    ],
    cs: [color(156, 156, 156),color(160),color(150),],
},

It checks the values in the array and will output the colour required, for example, 0 could be transparent, 1 could be yellow, 2 could be blue! you can add up to 10 values (0 – 9), You could put letters in too, but you’d need some conversion function. 


var Bs = function(block){
    strokeWeight(0.01);
    if(block === 0){
        // AIR
    }
    else{
        noStroke();
        for(var i = 0;i < 6;i ++){
            for(var j = 0;j < 6;j ++){
                var C = floor(BCs[block-1].d[i][j]);
                fill(BCs[block-1].cs[C]);
                rect(j*10, i*10, 10, 10);
            }
        }
    }
};

Then we have to store the images of the blocks. So instead of putting hundreds of rectangles every single frame,  we can store it in an image and it would just paste the image once every frame. It’s transparent too, Make sure you make a transparent background first, this is the best way to create images and then display them after:


var BGs = [];
var Block = function(){
    for(var i = 0;i < BCs.length+1;i ++){
        noStroke();
        background(0, 0, 0, 0);
        Bs(i);
        BGs.push(get(0, 0, 60, 60));
    }
    return{draw: function(x, y, w, r, block) {
        w = w || 60;
        pushMatrix();
        translate(x, y);
        rotate(r);
        image(BGs[block], -w/2, -w/2, w, w);
        popMatrix();
    }};
}();

Now we can easily call the blocks like this without any lag!

        Block.draw(30+i*60, 30+120+j*60, 60, 0, Bs[i][j].t+1);
This mining game wouldn’t work without the game-play and mining itself!

Now we want to focus on the gameplay! We want to focus on drawing the blocks first! This first piece of the for loop consists of increasing the alpha on the block so it shows, or technically it’s actually the other way around as we are just making the box that seems to be part of the background’s alpha decrease. We also display the box in between

/** DRAW THE BLOCKS **/
for(var i = 0;i < Bs.length;i ++){
    for(var j = 0;j < Bs[i].length;j ++){
        Bs[i][j].a +=1/180;
        Bs[i][j].a = constrain(Bs[i][j].a, 0, 1);
        Block.draw(30+i*60, 30+120+j*60, 60, 0, Bs[i][j].t+1);
        fill(64, 64, 64, 255-Bs[i][j].a*256);
        rect(i*60, 120+j*60, 60, 60);

The other bit is kind of confusing, first we check if the alpha is whole or otherwise we won’t let the cracks show nor will we let the player dig. If the alpha is 1, we will check another if statement if the broken amount is more or equal to one which then we will show the cracks.

We will have another if statement if the alpha conditions apply. It checks if the mouse is being pressed and if the cursor is in the boundaries of those positions. If not, then it will reset the break state, removing all progress.

Otherwise, the break speed will increase by the pickaxe level divided by 60. Which is the frames per second as well! it will check if the break amount is past one, which means it will do the very complex function of: Picking an amount of the material varying on the pickaxe; spawning particles with very well set instructions; Resetting the Alpha so the block completely disappears; Resetting the cracks and lastly, Changing the block to a different type. Whew, that’s a lot, 

        if(Bs[i][j].a === 1){
            if(floor(Bs[i][j].b*6) >= 1){Break.draw(i*60, 120+j*60, 60, 60, constrain(floor(Bs[i][j].b*6-1), 0, 5));}
            if(mouseIsPressed && mouseX > i*60 && mouseY > 120+j*60 && mouseX < 60+i*60 && mouseY < 60+120+j*60){
                Bs[i][j].b +=pickaxe/60;
                if(Bs[i][j].b >= 1){
                    var am = floor(random(1*pickaxe, 5*pickaxe));
                    for(var a = 0;a < am;a ++){
                        Ps.push({p:new P(60-15+i*60+random(-10, 10), 60-15+120+j*60+random(-10, 10), random(12, 30), "moveto", {gx: 300+Bs[i][j].t*50+15+random(-10, 10), gy: 35+15+random(-10, 10), r:0,rs:random(-5, 5), sp: 0, g:1+Bs[i][j].t})});
                    }
                    Bs[i][j].a = 0;
                    Bs[i][j].b = 0;
                    Bs[i][j].t = GetBlock(pickaxe);
                }
            }
            else{
                Bs[i][j].b = 0;
            }
        }
    }
}

Those are basically the main components, I won’t go thru and detail everything though! Because this would get too long and I’m already having so much fun playing this game! Speaking of Discord Miner, you can add the official (not mine) bot to your discord server using this shiny piece of text here! 

However the post isn’t over yet! I give you some challenges! Be sure to spin off my project and take a shot at these!

  • EASY: Add a delay between the appearance of the blocks!
  • MEDIUM: Add Emeralds to the game!
  • HARD: If you know code from the ups and downs, try creating an efficient bot that mines itself. (For example, make it look out for the ores like Diamond or Gold)

Good Luck! Hope you enjoyed this post! Be sure to leave a comment and a like on the post! 😀