This bot aims to provide a wallet and user association based on the user's discord account.
- Add an empty .env file beside this README.md file
- Create a discord app
- Click on the menu entry
Bot
(under Settings) and press "View Token" to get a token and copy it into the .env file asDISCORD_TOKEN=<token>
- Enable "MESSAGE CONTENT INTENT" under
Previliged Gateway Intents
at the bottom of this page - Goto the
OAuth2 > URL Generator
and activate thebot
andapplications.commands
scope - Within the bot perimssion section (below) check
View Channels
,Send Messages
,Embed Links
,Read Message History
andUse Embedded Activities
- Copy the generated URL and open it in a new tab
- Select the server you want to add the bot to and press "Authorize"
OPTIONAL
Change the verification level to "Highest" in the server settings under "Safety Setup" to make sure a user can only link accounts to wallets that have a verified phone number on DiscordIt prevents users from creating multiple accounts and linking them to different wallets
- In the Discord user settings under "Advanced" enable "Developer Mode" (this is needed to get the server and channel id)
- Right click on the server and copy the server id and add it to the .env file as
GUILD_ID=<server id>
- Create a new channel e.g. "🔗wallet-verification" which is only visible for verified users and ❗ make sure only the bot can send messages in this channel by changing the channel permissions ❗
- Right click on the channel and copy the channel id and add it to the .env file as
CHANNEL_ID=<channel id>
- If you don't have it yet, create a new role e.g. "Verified" that a user gets after accepting the rules of your server
- Right click on the role and copy the role id and add it to the .env file as
VERIFIED_ROLE_ID=<role id>
- The bot will send a message to a backend you would need to provide. Please make sure to implement the endpoints as described below in the "Endpoints" section
- Provide the backend within the .env file as
BACKEND_BASE_URL=<backend url>
- Run
npm install
to install all dependencies - Run
npm run build
to transpile the typescript code - Run
npm run start
to start the bot
GET
{{ BACKEND_BASE_URL }}
/is-verified/ - Checks if a user is verified and returnverified: true
orverified: false
POST
{{ BACKEND_BASE_URL }}
/start-verification - Starts the verification process and returns 200 if successful This endpoint expects a body like this, which needs to be stored for instance in a database:
{
"discordIdHash": "<hashedDiscordId>",
"secret": "<randomSecret>",
}
POST
{{ BACKEND_BASE_URL }}
/check-verification - This endpoint is called by the frontend to send signature along with the secret and hashed Discord id to the backend. The backend needs to check if the signature is valid and if the hashed Discord id and secret matches the one stored in the database.
Variable | Description |
---|---|
DISCORD_TOKEN | The token of the discord bot |
GUILD_ID | The id of the discord server |
CHANNEL_ID | The id of the discord channel |
VERIFIED_ROLE_ID | The id of the verified role |
BACKEND_BASE_URL | The base url of the backend |
FRONTEND_URL | The url of the frontend. The bot will link the user to this url with secret and hashed Discord id as url parameters |
Variable | Description | Default |
---|---|---|
DISCORD_VERIFICATION_BOT_SALT | It's an extra prefix added to the discord id before hashing to increase the security | |
BACKEND_BASIC_AUTH_ENABLED | Enables or disables basic auth | false |
BACKEND_BASIC_AUTH_USER | The username of the basic auth | |
BACKEND_BASIC_AUTH_PASSWORD | The password of the basic auth | |
BOT_MESSAGE_WELCOME | A message the bot sends alongside the verification button | Click the button below to verify your wallet |
BOT_BUTTON_LABEL | The label of the verification button | Start Wallet Verification |
BOT_MESSAGE_RULES_NOT_ACCEPTED | The message the bot sends in case the user does not have the verified role |
Hi ${USERNAME}, you need to accept our terms and conditions by reacting with a 🚀 emoji to the message within the verification channel. Click the button again once you have accepted the terms and conditions. |
BOT_MESSAGE_SUCCESS | A message the bot sends together with the frontend link to finish the verification process on your website | Thank you $${USERNAME}, please follow this link to finish the verification process on our website!` |
BOT_SUCCESS_BUTTON_LABEL | The label of the button the bot sends to finish the verification process in the frontend | Finish Wallet Verification |
BOT_MESSAGE_ALREADY_VERIFIED | A message the bot sends in case the user is already verified | Hi ${USERNAME}, you have already verified your wallet! |
BOT_ERROR_MESSAGE | A message the bot sends in case of an error | Hi ${USERNAME}, something went wrong. Please try again later! |
We use a mix of tsc -w and nodemon to watch for changes and restart the bot. Just run the following command to start the bot in development mode:
npm run dev