Don't wanna be here? Send us removal request.
Text
some very very basic javascript
ok i know the way i code is incredibly sloppy but i dont care enough to fix it so everything is done on if/else. this means anything you want to take priority needs to come FIRST in the code
for example, if ur bot responds to ‘jimin’ but it also has a different response to ‘i love jimin’ u need to decide which is more important. if the ‘jimin’ command is first, the bot will respond to this one only, even if the message sent says ‘i love jimin’.
all ur commands MUST end in ‘else’ like this, UNLESS it is the very last command in the document in which case dont put ‘else’ or nothing will work
so first open the bot.js code document. paste this
const Discord = require("discord.js"); const client = new Discord.Client();
client.on("ready", () => { console.log("lets go!"); client.user.setActivity("WHATEVER")});
client.on("message", (message) => { all ur code goes in this space here. dont edit the other bits unless u know what java but if u do then why are u reading this! also remove this message lol }); client.login("URBOTTOKENHERE");
so where it says URBOTTOKENHERE put ur token that u copied earlier. where it says WHATEVER is whats going to appear on ur bots playing status
ok so now actual code! im including a load of different bits so u can do what u want
responding to messages
in this case, if the message includes ‘jimin’ the bot will respond with the emoji no matter where the command is in the message, and no matter the capitalisation. if u want a specific case in ur command just get rid of toLowerCase().
if (message.content.includes("YOURCOMMAND")) {
message.channel.send("YOURRESPONSE");
} else
if u want the bot to respond to something thats specifically at the start of a message, change ‘includes’ to ‘startsWith’. this is how i do commands with a ! at the start like !kiss but u can use any punctuation or none at all. try and use a punctuation that doesnt overlap with another bot in ur server
if (message.content.startsWith("YOURCOMMAND")) {
message.channel.send("YOURRESPONSE");
} else
sending pictures
exactly the same as sending text, but you include a link to an online file
if (message.content.toLowerCase().includes("YOURCOMMAND")) { message.channel.send("YOURRESPONSE", {files: ["YOURFILELINK"]}) } else
the response part is optional, just remove it if u only want to send the image
random messages
u can get the bot to send a random message from a selection of messages by randomly assigning them numbers
if (message.content.startsWith("YOURCOMMAND")) { let answer = ["RESPONSE1", "RESPONSE2", "RESPONSE 3"] let number = Math.floor((Math.random() * answer.length)) message.channel.send(answer[number]); } else
u can also do this with images, just paste the file link where the responses go
u can use this random response things to create little games like rock paper scissors, or an 8ball
mentioning users
u can get the bot to mention users in the server
if (message.content.startsWith("YOURCOMMAND")) { message.channel.send(message.mentions.users.first() + ", hello from" + message.author.toString() ); } else
here, message.mentions.users.first() is the user mentioned in your message, while message.author.toString() is the author of the message. u can put things around in any order u want and u dont have to include both idk ask me if u need help haha
bot responds to itself HELP!!!
if ur bots response contains the command, for example if jiminbot’s response to ‘jimin’ was to say ‘im jimin’, he would then repeat ‘im jimin’ over and over again as the command is in his own messages. to resolve this add
if (message.author.bot) return;
ok thats all ill include but if u want to do anything else lmk and ill try to help also if something goes wrong lmk and ill help.. it probs will cus im bad at explaining and in coding literally 1 wrong full stop can fuck the whole thing updfjkfl also DONT FORGET ur last command does Not have the ‘else’ afterwards. like htis
ok so. once ur code is all done and finished we gotta run the bot. to do this open the command window again FROM THE FOLDER again like last time and type
node bot.js
and it should run if not im so sorry please ask me for helpppp
0 notes
Text
discord bot tutorial
im just doing it on tumblr cus its easy :pensive:
first install node js
and then visual code but u dont need it for a while
then u go to here and log in to discord, and create an application
once u created it, on the left hand side panel theres a button that says Bot, click it and click create a new bot
ok now go back to the general info tab
and on this page under ur app’s name it should have the client id, paste this link into your browser but replaces YOURCLIENTIDHERE with... your client id...
https://discordapp.com/oauth2/authorize?&client_id=YOURCLIENTIDHERE&scope=bot&permissions=3147776
and this allows u to add the bot to a server. i recommend making a server with only u and the bot in it so u can test everything and make sure it works before u add it to a server with other people cus example sometimes when i fuck up my code jiminbot starts spamming shit and its annoys everyone else
Ok next step is make a folder on ur computer, just name it something like Bot or whatever that u will remember idk
but first u need to get ur bots token, its on the bot page on the discord site just copy it
now u need to open the visual code software u installed earlier, and u need to save 3 files to the folder
FILE 1:
paste this into visual code but replace YOURTOKEN with your token that u copied SAVE IT AS auth.json it has to be .json not .txt or anything else or i will be mad
{ “token”: “YOURTOKEN” }
FILE 2:
paste this into a NEW code file, replace all the stuff with whatever u want and save as package.json , again if its not .json i will be pissed
{ “name”: “YOURBOTNAME”, “version”: “1.0.0”, “description”: “YOURBOTDESCRIPTION”, “main”: “bot.js”, “author”: “YOURNAME”, “dependencies”: {} }
FILE 3:
this file is ur bots code, just make it and save it as bot.js and ill come back to it later
ok before u can do code u have to install dependencies which is annoying bc u need different ones for different things but basic ones should be fine.. u need to open ur command prompt FROM ur bot folder. u right click on the folder and it should say Open Command Window here, sometimes on windows its called powershell and thats ok its the same. on mac sometimes u have to enable an option to do it in preferences i think
so once u open the command window paste this
npm install discord.io winston --save
and press enter. then paste this
npm install discord.js
and press enter again. ok done
for coding the actual bot go to this post i made them seperate so the post wasnt too longgg
1 note
·
View note