![]() ![]() First of all, we’re listening to a ready event. The bot variable is actually our Discord client through which we’ll interact. The last line of the above snippet shows how we pass the token to the login function in order to get access to the bot we’ve created. This allows us to use the TOKEN variable we’ve defined through. We first load the environment variables we’ve defined through requiring the config from the environment. config ( ) const Discord = require ( 'discord.js' ) const bot = new Discord. Let’s take a look at the index.js file located in the root of the project: require ( 'dotenv' ). You should see a similar message that indicates that the bot has joined the channel. If you want to double-check that your bot got added, go to the General channel. If you’re able to successfully add the bot to your server, you should see the following success screen. Let’s select our newly created discord_playground.Ĭlick the Authorize button to add the bot to our server. You’ll find an overview that asks you which server you want to add the bot to. Lastly, copy this URL and paste it in your favorite web browser. When you select both options, notice the number has changed for the permissions parameter in the authorization URL. We need the permission to read message history so we can detect users’ requests. We want the bot to be able to Send Messages and Read Message History. If we scroll further down, you’ll find the bot permissions section. However, the permissions=0 section indicates that we haven’t set permissions yet. You might notice that the authorization URL below has changed now. As we just want to enable a simple bot, we pick the bot option. Here we can define the scope for our bot. Navigate to the OAuth2 section under the Settings menu. Thirdly, we want to define the permissions for the bot and add it to our Discord server. Step 3: Define Permissions and Add Bot to Server Copy this authorization token and write it down somewhere, as we’ll need it later to connect to our bot user. When the bot has been built, you get an overview of your custom bot. Discord will build our my-greeter-bot application and add a bot user to it. Now, click on the Bot menu option in the Settings menu. This secret will be used later as the authorization token. You’ll see information like a client ID and client secret. When the application has been created, you’ll see the overview of the newly created my-greeter-bot application. By clicking the Create button, Discord will create an API application. Next, you’ll see a pop-up that asks you to input a name for your application. Let’s create a new application by clicking the New Application button. To register the bot, go to the Discord Developers Portal and log in with your account.Īfter logging in, you should be able to see the dashboard. When we want to control our bot via code, we need to register the bot first under our Discord account.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |