This project allows you to manage user access to your Discord bot via OAuth2 authorization. Users must authorize the bot to join servers on their behalf. It provides useful commands for server management, a simple setup process, and a robust database to handle user information.
This script is potentially malicious and unethical. It can be used for malicious purposes, such as stealing user tokens, personal information, and other sensitive data. Using this script for malicious purposes without the user's consent is illegal and violates ethical guidelines. Do not use this script without proper authorization.
- Manage user access to your server via OAuth2.
- View and control users in the database.
- Refresh and manage bot commands dynamically.
/ping
: Displays the bot's current ping./refresh
: Refreshes the bot's slash commands./links
: Sends useful links such as OAuth2 and bot invitation links./joinall
: Adds all users from the database to the server./join
: Adds a specified number of users to the server./users
: Displays the total number of users in the database./clear
: Deletes a specified number of messages in a channel.
- Node.js v16.15 or later
- Discord bot token
- SQLite database
- Clone this repository:
git clone https://github.com/AstraaDev/Discord-OAuth2.git
- Navigate to the project directory:
cd Discord-OAuth2
- Install dependencies:
npm install
- Edit the
.env
file provided in the repository:ClientID=YOUR_CLIENT_ID_HERE ClientSecret=YOUR_CLIENT_SECRET_HERE PORT=1500 BotToken=YOUR_BOT_TOKEN_HERE
- Modify
YOUR_USER_ID_HERE
insrc/bot.js
with your Discord account ID. Only these IDs will have access to the bot commands. - Replace
YOUR_CLIENT_ID_HERE
andYOUR_REDIRECT_URI_HERE
insrc/bot.js
to match your application's OAuth2 settings.
Start the bot by running:
node bot.js
Start the Express server:
node index.js
To create your Discord bot and retrieve the necessary credentials:
-
Go to the Discord Developer Portal: Visit the Discord Developer Portal and log in with your Discord account.
-
Create a New Application:
- Click on "New Application."
- Provide a name for your bot and click "Create."
-
Generate the Client ID and Client Secret:
- Go to the "OAuth2" tab.
- Under "General Information," copy your Client ID and Client Secret. These will be used in your
.env
file.
-
Add a Bot User:
- Navigate to the "Bot" tab.
- Click on "Add Bot" and confirm.
- Copy the Bot Token by clicking on "Reset Token." Add this token to your
.env
file asBotToken
.
-
Set Up OAuth2 Redirects:
- In the "OAuth2" tab, under "Redirects," add your redirect URI (e.g.,
http://localhost:1500/api/auth/discord/redirect
).
- In the "OAuth2" tab, under "Redirects," add your redirect URI (e.g.,
-
Configure Permissions:
- In the "OAuth2" tab, use the URL Generator to set the bot's permissions and scopes (e.g.,
bot
,applications.commands
). - Generate the invitation link and use it to invite your bot to a server.
- In the "OAuth2" tab, use the URL Generator to set the bot's permissions and scopes (e.g.,
SQLite is used to store user information:
username
: The username of the authorized user.discord_id
: The Discord ID of the user.access_token
: The OAuth2 access token.refresh_token
: The OAuth2 refresh token.
- For support, join the Discord Server.
- Contributions are welcome. Feel free to open an issue or create a pull request.