docs/discord.rst
:orphan:
.. _discord-intro:
In order to work with the library and the Discord API in general, we must first create a Discord Bot account.
Creating a Bot account is a pretty straightforward process.
Make sure you're logged on to the Discord website <https://discord.com>_.
Navigate to the application page <https://discord.com/developers/applications>_
Click on the "New Application" button.
.. image:: /images/discord_create_app_button.png :alt: The new application button.
Give the application a name and click "Create".
.. image:: /images/discord_create_app_form.png :alt: The new application form filled in.
Navigate to the "Bot" tab to configure it.
Make sure that Public Bot is ticked if you want others to invite your bot.
.. image:: /images/discord_bot_user_options.png :alt: How the Bot User options should look like for most people.
Copy the token using the "Copy" button.
.. warning::
It should be worth noting that this token is essentially your bot's
password. You should **never** share this with someone else. In doing so,
someone can log in to your bot and do malicious things, such as leaving
servers, ban all members inside a server, or pinging everyone maliciously.
The possibilities are endless, so **do not share this token.**
If you accidentally leaked your token, click the "Regenerate" button as soon
as possible. This revokes your old token and re-generates a new one.
Now you need to use the new token to login.
And that's it. You now have a bot account and you can login with that token.
.. _discord_invite_bot:
So you've made a Bot User but it's not actually in any server.
If you want to invite your bot you must create an invite URL for it.
Make sure you're logged on to the Discord website <https://discord.com>_.
Navigate to the application page <https://discord.com/developers/applications>_
Click on your bot's page.
Go to the "OAuth2 > URL Generator" tab.
.. image:: /images/discord_oauth2.png :alt: How the OAuth2 page should look like.
Tick the "bot" checkbox under "scopes".
.. image:: /images/discord_oauth2_scope.png :alt: The scopes checkbox with "bot" ticked.
Tick the permissions required for your bot to function under "Bot Permissions".
Please be aware of the consequences of requiring your bot to have the "Administrator" permission.
Bot owners must have 2FA enabled for certain actions and permissions when added in servers that have Server-Wide 2FA enabled. Check the 2FA support page <https://support.discord.com/hc/en-us/articles/219576828-Setting-up-Two-Factor-Authentication>_ for more information.
.. image:: /images/discord_oauth2_perms.png :alt: The permission checkboxes with some permissions checked.
Now the resulting URL can be used to add your bot to a server. Copy and paste the URL into your browser, choose a server to invite the bot to, and click "Authorize".
.. note::
The person adding the bot needs "Manage Server" permissions to do so.
If you want to generate this URL dynamically at run-time inside your bot and using the
:class:discord.Permissions interface, you can use :func:discord.utils.oauth_url.