-
Notifications
You must be signed in to change notification settings - Fork 293
Creating a discord bot & getting a token
Creating a bot user in discord is really easy!
-
First, go to Discord's Developer Portal and click "New Application":
-
Now give your bot a name, read the linked terms of service, and click create.
On the new screen you will be able to change your bot profile image, bot description and several other details.
-
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!".
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.
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.
-
First, fetch your bot's "client ID" back from the "General information" tab:
-
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)
-
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!
You may then be required to fill in a CAPTCHA, and will then be presented with an "Authorized" panel!
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!
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.
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!