banner



How To Add A Verfied Command To Discord Js

Getting Started - Long Version

Then, y'all want to write a bot and yous know some JavaScript, or maybe even node.js. You want to exercise cool things similar a music bot, tag commands, random paradigm searches, the whole shebang. Well you're at the correct place!

{% hint way="info" %} This is the long version with a whole lot of useless blabbering text, jokes and explanations.
Here's the TL;DR (brusque) version {% endhint %}

This tutorial will go you through the offset steps of creating a bot, configuring it, making it run, and calculation a couple of commands to it.

Pace 1: Creating your App and Bot business relationship

The outset step in creating a bot is to create your own Discord application. The bot volition use the Discord API, which requires the cosmos of an business relationship for hallmark purposes. Don't worry though, information technology'southward super elementary.

Creating the App account

To create the application, head to the Discord application folio. Assuming you're logged in (if not, do so now), you'll achieve a page that looks like this:

The application page

Click on (you guessed it!) New Application. This brings up the following modal, in which you should but enter a name for the application (this will be the initial bot username). Click Create which volition create the awarding itself.

New application modal

The Application ID on the page will be your bot's user ID. The application description is used in the bots About me section. And so feel free to add together a description of your bot in nether 190 characters.

{% hint style="info" %} Whilst the page clearly indicates a maximum of 400, only 190 volition be displayed in the About me department.{% endhint %}

The created application

Create the bot business relationship

After creating the awarding, we need to create the Bot User. Become to the Bot section on the left, and you volition be greeted with the post-obit screen.

Build-a-bot

Finally click on Add Bot, and then Yep, Exercise it to create your bot.

Are you sure?

At that place'due south a few things y'all can change here and well-nigh importantly the token.

Making the bot

  • Icon to change the bot'south avatar (can also exist done with discord.js)
  • Username to change your bot's username on Discord (this can also be washed through lawmaking).
  • Token This is your bot's token, which will be used when connecting to discord. See the department below for details.
  • Public bot This toggles the ability for other users to add your bot to their server. You can plough this off during evolution to prevent random users inviting information technology.
  • Require Oauth2 Code Grant Don't cheque this. Only, don't. Information technology'due south not useful to you and volition cause problems if you turn it on.
  • Privileged Gateway Intents Now this is of import, if your bot is checking presence data, or downloading the fellow member list, you will demand to toggle either or both of these, for at present they're non needed. But please note, if your bot reaches 100 servers you will need to be whitelisted and verified to use these.

Add your bot to a server

Okay and so, this might exist a fleck early to practise this but it doesn't really affair - fifty-fifty if you haven't written a single line of code for your bot, you can already "invite" it to a server. In gild to add a bot, you need Manage Server or Ambassador permissions on that server. This is the only fashion to add together a bot, it cannot utilize invite links or whatever other methods.

To generate the link, click on OAuth2 in the app page (it's to a higher place Bot), and scroll downwards to Scopes. Check the bot scope to generate a link, if you're planning on calculation slash commands make sure to click applications.commands also.

Usually, bots are invited with the specific permissions which are given to the bot's role which cannot be removed unless you kick and reinvite the bot. This is optional, only you can set those permissions in the Bot page, scrolling downwards to the Bot Permissions section. Cheque any permissions your bot requires. This modifies the invite link to a higher place, which y'all can so share.

One time you lot have the link, y'all can copy it to a browser window and visit information technology. When you do this, Y'all go shown a window letting you choose the server where to add together the bot, simply select the server and click Qualify.

Inviting the bot

{% hint style="info" %} You demand to be logged in to Discord on the browser with your account to run into a listing of servers. Yous tin merely add a bot to servers where you have Manage Server or Administrator permissions. {% endhint %}

Getting your Bot Token

{% hint way="danger" %} Alright so, big flashy warning, PAY ATTENTION. This next part is actually, really important: Your bot'due south token is meant to exist Clandestine. It is the way by which your bot authenticates with the Discord server in the same style that you login to Discord with a username and countersign. Revealing your token is like putting your countersign on the internet, and anyone that gets this token can use your bot connexion to do things. Like delete all the messages on your server and ban everyone. If your token ever reaches the internet, change it immediately. This includes putting information technology on pastebin/hastebin, having it in a public github repository, displaying a screenshot of it, anything. GOT It? Proficient!, Github has partnered with Discord to invalidate your token if information technology's found within your code repository and message you lot via a System message on Discord. {% endhint %}

With that alarm out of the mode, on to the adjacent step. The Token, as I but mentioned, is the way in which the bot authenticates. To go it, go to the Bot section of the app folio, and then click Copy to copy information technology to the clipboard. Yous tin can also view your token here if you lot wish. Non forgetting that e'er important Regenerate cardinal if your token is compromised:

NEVER SHARE YOUR TOKEN! This cannot be overstated.

Stride 2: Getting your coding environs ready

This might go across saying but I'll say it anyway: You lot tin't just first shoving bot code in notepad.exe and expect it to work. In gild to use discord.js you will need a couple of things installed. At the very least:

  • Get Node.js version 16.vi or higher (earlier versions are non supported). Download for windows or if y'all're on a linux distro, via package manager.
  • Get an bodily lawmaking editor. Don't use notepad or notepad++, they are not sufficient. VS Code , Sublime Text 3 and Atom are often recommended.

Once you have the required software, the side by side step is to prepare a space for your code. Delight don't just put your files on your desktop information technology's... unsanitary. If yous take more than than one hard drive or partition, you could create a special place for your development project. Mine, for example, is D:\develop\ , and my bot is D:\develop\guide-bot\ . Once you've created a folder, open your CLI (command line interface) in that folder. Linux users, you lot know how. Windows users, hither'south a play a trick on: SHIFT + Right Click in the folder, then choose the "secret" command Open PowerShell window here. Magic!

And at present ready for the next step!

Installing Discord.js

And then you lot have your CLI fix to go, in an empty folder, and you merely wanna offset coding. Alright, agree on one last 2nd: let's install discord.js. But first nosotros'll initialize this folder with NPM, which volition ensure that any installed module volition be here, and nowhere else. Simply run npm init -y and so hit Enter. A new file is created called package.json, click here for more than info near it.

And now we install Discord.js through NPM, the Node Package Manager:

npm i discord.js At the time of writing this v13 hasn't been released yet.

Installing the packages

This volition take a couple of heartbeats and display a lot of things on screen. Unless you lot have a big fat ruby-red bulletin saying information technology didn't work, or packet not plant, or whatever, you're good to go. If you look at your folder, you'll detect that there's a new binder created here: node_modules . This contains all the installed packages for your projection.

Getting your commencement bot running

{% hint style="info" %} I honestly consider that if y'all don't understand the code you're about to run into, coding a bot might not be for you lot. If you do not understand the following sample, please go to CodeAcademy and learn Javascript first. I beg of y'all: end, driblet, and roll. {% endhint %}

Okay finally, nosotros're ready to first coding. \o/ Let's take a look at the virtually basic of examples, the ping-pong bot. Here's the lawmaking in its entirety:

              const              {              Client,              Intents              }              =              require              (              "discord.js"              )              ;              // The Client and Intents are destructured from discord.js, since it exports an object by default. Read upward on destructuring hither https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment              const              client              =              new              Client              (              {              intents:              [              Intents              .              FLAGS              .              GUILDS              ,              Intents              .              FLAGS              .              GUILD_MESSAGES              ]              }              )              ;              client              .              on              (              "prepare"              ,              (              )              =>              {              console              .              log              (              "I am gear up!"              )              ;              }              )              ;              client              .              on              (              "messageCreate"              ,              (              message              )              =>              {              if              (              message              .              content              .              startsWith              (              "ping"              )              )              {              message              .              channel              .              send              (              "pong!"              )              ;              }              }              )              ;              customer              .              login              (              "SuperSecretBotTokenHere"              )              ;            

{% hint style="info" %} The variable client here is used an an example to correspond the <Client> class. Some people phone call it bot, just you can technically call it any you want. I recommend sticking to client though! {% endhint %}

Okay permit's just... really get this guy to work, considering this is literally a functional bot. So let's make information technology run!

  1. Copy that code and paste information technology in your editor.
  2. Replace the cord in the client.login() function with your token
  3. Salve the file as index.js.
  4. In the CLI (which should still be in your projection folder) type the post-obit command: node index.js

If all went well (hopefully information technology did) your bot is now continued to your server, it's in your user list, and prepare to answer all your commands... Well, at to the lowest degree, ane control: ping. In its electric current state, the bot volition reply "pong!" to whatever message that starts with, exactly, ping. Let'due south demonstrate!

Ping?, Pong!

Success! You at present accept a bot running! As you probably realize by now I could probably blabber on from here, showing you lot a bunch of stuff. But the telescopic of this tutorial is completed, so I'll shut upwards now! Ciao!

The Next Step?

Now that y'all have a basic, functional bot, information technology'south fourth dimension to start calculation new features! Caput on over to Your Start Bot to go along on your journey with adding new commands and features!

Annex: Getting assistance and Support

Before you first getting support from Discord servers to help you lot with your bot, I strongly advise taking a look at the following, very useful, resources.

  • Discord.js Documentation : For the love of all that is (un)holy, read the documentation. Yes, it will exist alien at commencement if yous are not used to "developer documentation" just it contains a whole lot of information well-nigh each and every feature of the API. Combine this with the examples above to come across the API in context.
  • An Idiot'due south Guide is some other great channel with more material. York'south guides are great, and he continues to update them.
  • Evie.Codes on YouTube: If you prefer video to words, Evie'south YouTube series (which is skillful, though no longer maintained with new videos!) gets you started with bots.
  • An Idiot's Guide Official Server: The official server for An Idiot's Guide. Full of friendly helpful users!
  • Discord.js Official Server: The official server has a number of competent people to help you, and the development team is in that location as well!

How To Add A Verfied Command To Discord Js,

Source: https://github.com/AnIdiotsGuide/discordjs-bot-guide/blob/master/getting-started/getting-started-long-version.md

Posted by: grantbance1994.blogspot.com

0 Response to "How To Add A Verfied Command To Discord Js"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel