discord.js API Token bot creation

Creating API Tokens and Bots for discord.js

To use discord.js, which allows you to programmatically control Discord from Node.js, we create and configure API tokens and bot accounts, and add them to servers.

Shou Arisaka
3 min read
Oct 30, 2025

To use discord.js, which allows you to programmatically control Discord from Node.js, we create and configure API tokens and bot accounts, and add them to servers.

To operate Discord with Node.js’s discord.js, you need API tokens and bot accounts. The flow is: create an API, create a bot account linked to that API, generate a URL with permissions set from the created bot account, click that URL in a browser or Discord app logged into Discord to add that bot account to any server.

Creating API and Bot Account

First, create an API and bot account in Discord.

Navigate to the API portal page.

Discord Developer Portal — My Applications

Click “New application” or “Create new application” You’ll be asked for a name, so enter an appropriate name. Here, we used “hogehoge” as an example.

Image

Select “bot” from the menu on the left side of the screen, click “add bot” or “Add bot”

Image

At this point, you can copy/display the created bot’s ID (e.g., hogehoge#1234) and the API token. Click copy to copy the API token to your clipboard. This will be used later in Node.js.

Image

Reference:

Setting up a bot application | Discord.js Guide

Generating OAuth2 URL

Generate an OAuth2 URL. This is the step that allows you to share the bot with other users and enables other users or admin users to add that bot to the Discord server they manage.

From the menu on the left side of the screen, proceed to OAuth2 > URL Generator. You’ll be asked to select scopes for permissions, so here select “bot” and “applications.commands”.

OAuth2 URL generator, Select the bot and applications.commands, [Adding your bot to servers | Discord.js Guide](https://discordjs.guide/preparations/adding-your-bot-to-servers.html#bot-invite-links)
![Image](/images/blog/sharex_screenshot_a30ce4c7-cef7-405c-965f-a29b0471_fb18b801.png)

Scroll down the screen and set permissions. Here we set permissions as an example like this. After setting permissions, copy the displayed URL from the copy button in the bottom right of the screen.

Example: send messages manage messages manage threads read message history mention everyone add reactions use slash commands read messages/view channels

Image

Reference:

Adding your bot to servers | Discord.js Guide

Adding Bot Account to Any Server

Open the copied URL in a browser or Google Chrome logged into Discord.

Select the server you want to add the bot to in “select server”. Click “continue” and confirm the authentication. Once you can see the completion icon, you should be able to confirm that the bot has been added to the server.

Image

Share this article

Shou Arisaka Oct 30, 2025

🔗 Copy Links