Skip to content

Creating a discord bot & getting a token

Edward Jones edited this page Nov 15, 2020 · 11 revisions

Creating a bot

Creating a bot user in discord is really easy!

  1. First, go to Discord's Developer Portal and click "New Application":

    The "new application" button can be found in the top right of the developer portal page

  2. Now give your bot a name, read the linked terms of service, and click create.

    New application form, with a box to input the bot's name

    On the new screen you will be able to change your bot profile image, bot description and several other details.

    The "general information" page of a discord bot user shows a selection box for the app icon and a name and description form

  3. Finally, to create the bot user itself (rather than merely the application flow), click "Bot" on the left sidebar. Then click "Add Bot", and after reading the confirmation prompt, "Yes, do it!".

    The "bot" button is under "settings" on the left sidebar, and the "add bot" button can be found in the "Build-A-Bot" panel The confirmation popup warns that this action is irrevocable, and presents a choice between "Nevermind" and "Yes, do it!" to continue with the action

Fetching your bot's token

Once you've already created a bot, you can access the bot's page on the developer portal, and under the "Bot" tab again, use the "Click to Reveal Token" button under your bot username – alternatively, simply click "Copy" and the token will be copied to your clipboard directly. This token can then be embedded in your config.json file for discord-irc. Note that this token should be kept private, and must be reset if it is leaked – see "Token security" for more information.

After adding the bot successfully, the bot page will now show a section for the token, with "copy" and "regenerate" buttons

Adding your bot to your server

Now it's time to invite your bot to your server! Don't worry about the bot being up and running for this next step.

  1. First, fetch your bot's "client ID" back from the "General information" tab:

    Your app's client ID can be found under the name and description boxes of "General Information"

  2. Head to the following URL, replacing YOUR_CLIENT_ID_HERE with the ID you grabbed above: https://discord.com/oauth2/authorize?scope=bot&permissions=0&client_id=YOUR_CLIENT_ID_HERE

    (more information can be found about this URL in Discord's developer docs)

  3. You'll be presented with a consent dialog, explaining what's necessary to attach the bot to your server. Please read this carefully, then select the right server from the dropdown, and click Authorize!

    The consent dialog provides some information about the application and you, and explains that you need "Manage Servers" permission to add the bot to a server

    You may then be required to fill in a CAPTCHA, and will then be presented with an "Authorized" panel!

    The authorized panel presents no additional information and can be safely closed

Note: your bot will connect to your server, but may not have specific permissions that you want. If you want to create an automatic role for it in your server, go to "Bot" tab in your bot settings page and scroll down. Select the desired permissions, and copy the result number to the URL you previously used to access the consent dialog (e.g. instead of &permissions=0, use &permissions=131072 to provide it with "Mention Everyone" permissions).

That's it! Now you can start your bot and enjoy chatting!

Token security

IMPORTANT: you should NEVER give your bot's token to anybody you do not trust, and especially never publish it in a public location, such as a Git repo. The token gives full access to your bot account, and a malicious actor could use it to hijack the bot (ranging from the irritating – such as leaving all your servers, and breaking your bridge – to the much more serious – such a spamming unfavorable links or deleting messages and channels in servers where it has moderator permissions). Keep your token secret!

However, if your token ever does get compromised or you suspect it has been, not all is lost: the very first thing you should do is go to your Discord Apps page, select the relevant bot, and then under the "Bot" tab of the left sidebar, regenerate the token in the same location you originally accessed the token. This will give you a brand-new unique token that you can update in your bot's config.

The "bot token" panel, same as in the "Fetching your bot's token" header above

Ensure to take the appropriate measures to secure this token where it can't be leaked or compromised (especially if you've already been bit by this once!). If you would like to build a bot based on discord-irc and open source your bot's code, you can store the token in a separate file outside the main repository, or else add this file to .gitignore to ensure it isn't published with the rest of your bot – discord-irc provides its --config flag for this purpose.

Good luck!