Learn to Code via Tutorials on Repl.it!

← Back to all posts
Creating a Discord bot in Repl.it
h
Indigos1st (2)

Creating a Discord bot in Repl.it

In this tutorial we are going to show you how to create a Discord bot in Repl.it, i'm going to assume you have created your bot and added it to your server. Look at our project and read index.js we will write what we wrote here as well

Useful documentation

Discord.js
Discord.js guide

what are the packages used?

discord.js: discord.js is a package that links javascript to the discord app

djs-commands: this is our command handeler package, we will be able to create multiple .js files insted of just one large .js files

express: we use express so we don't have to code the html in one file, insted we create a file linked to our main, "index.js", and we link "keep_alive.js" with our html file, which can we found in /views/index.html this makes our program easier to read

winston: winston create a file named "log" which stores all our logs.

chalk: we use this package so we can customize the terminal better so it is easier to read

how create a .env file and what is a .env file?

a .env file is an environmental variable it can't be coppied if another person remixes our project. Because with the free version of repl.it everyone can see our code a .env is helpful. we cannot show people our token because then they can login to our bot and code it

to create a .env file we first add a file named ".env" and nothing else, next we add this:

DISCORD_BOT_SECRET=YOURTOKEN

don't use any spaces in this file because then it wont work.

conclusion

now we have finished all of that and your bot is setup, you can code however you want your bot! have fun coding.

Comments
hotnewtop
SummerCube (1)

I am not able to make .env file for some reason