Discord allows users to create Bots and invite them to servers. Discord allows users to create applications that interact with the API. API documentation is listed here.
The community-driven but official Discord API server can be accessed here.
Regular bots have dedicated bot accounts created through the developer portal. Bot accounts have different restrictions and features than user accounts. To invite a server bot to your guild, you need to have the Manage Server permission, and you need to authorize it with an authorization link specific to that bot. To invite a bot; click the authorization link, select a server, deny or allow it to have the permissions listed on the page, and click 'Authorize'. To remove a bot from your server, simply kick or ban it like you would any other user. Reinviting a bot account that was already banned from the server will unban it. Bot accounts have a bot tag next to their name to distinguish it from regular users. If you want to create your own bot, you need to create it through Discord's application page. The applications page is listed here.
Selfbots are when a user uses the Discord API to automate their account. A self bot runs directly on your account by using your user token to automate itself. Selfbots are against the Discord API OAuth policy and can lead to an account termination. In contrast to userbots, selfbots only respond to the user account it is running on. Do not give anyone your user token. If someone gets your user token, they can do serious damage to your account, including reading messages, sending messages and mess with any server you have permissions on.
Userbots are fully functioning bots that run through a regular account. This is against the Discord Terms of Service. Like other Terms of Service violations, userbots can be reported to Discord Trust & Safety at email@example.com..
Users have created many different libraries that make using the Discord API easier.
Discord has a list of curated libraries "that conform to [Discord's] APIs standards around authentication and rate limiting."
On April 7th, 2020, Bots Verification was introduced. Each bot that reaches over 75 simultanious guilds has a chance of getting verified.
Starting October 7th, 2020, unverified bots will not be able to join more than 100 servers (if it's already in more than 100 of them, you won't be able to invite it) and won't be able to access Privileged Intents.