-
-
Notifications
You must be signed in to change notification settings - Fork 0
Installation Guide
A Discord bot that automatically syncs user roles based on product purchases from SourceXchange.
This guide shows two ways to run the bot: locally with Node.js or using Docker.
- Discord account with server admin permissions
- SourceXchange account
- Git
- Node.js 18+ and npm (for local run)
- Docker (for container run)
git clone https://github.com/KingIronMan2011/sourcexchange-sync-bot.git
cd sourcexchange-sync-botCopy the example env file and edit with your values:
cp .env.example .envRequired vars in .env:
DISCORD_TOKEN=
CLIENT_ID=
API_TOKEN=
PRODUCT_ID=
DISCORD_ROLE_ID=
NODE_ENV=production
npm installnpm startYou should see:
Logged in as YourBotName#1234
Slash commands deployed
Pull and run the prebuilt image:
docker pull kingjulian2011/sourcexchange-bot:latest
docker run --rm --env-file .env --name sourcexchange-bot kingjulian2011/sourcexchange-bot:latestdocker build -t sourcexchange-bot:local .
docker run --rm --env-file .env --name sourcexchange-bot sourcexchange-bot:localThe repository includes docker-compose.yml that uses the prebuilt image by default.
Start the service:
docker compose up -dRebuild (if you change Dockerfile or want a local build):
docker compose build
docker compose up -dA GitHub Actions workflow builds and pushes images to Docker Hub and GHCR on push and workflow_dispatch. Add these repo secrets to enable Docker Hub pushes:
- DOCKER_USERNAME
- DOCKER_PASSWORD
GHCR uses the repository GITHUB_TOKEN by default.
- Go to the Discord Developer Portal → New Application.
- Save the Application ID as
CLIENT_ID. - Create a Bot user and copy the bot token →
DISCORD_TOKEN. - Enable Server Members Intent under Bot settings if required.
- OAuth2 → URL Generator
- Select scopes:
bot,applications.commands - Select permissions:
Send Messages,Use Slash Commands,Manage Roles - Open generated URL and invite to your server.
- Product ID: check your product URL / seller dashboard on SourceXchange.
- Discord Role ID: enable Developer Mode → right-click role → Copy ID.
Keep secrets out of source. Use repository secrets for CI and .env for local runs. Example .env.example is provided.
- Check logs:
- Docker:
docker logs -f sourcexchange-bot - Local: console output from
npm start
- Docker:
- Verify env values and that the bot has Manage Roles and required intents.
PM2 example:
npm install -g pm2
pm2 start bot.ts --name sourcexchange-bot --interpreter node
pm2 save
pm2 startupCreate a systemd unit to run the container or pm2 service (not included here).
- Do not upgrade global npm inside images unless pinned to a verified patched version.
- Keep dependencies and base images up to date and commit lockfiles.
- See repository docs for Configuration, User Guide and Troubleshooting.
# SourceXchange Sync Bot
A Discord bot that automatically syncs user roles based on product purchases from [SourceXchange](https://www.sourcexchange.net).
## Installation Guide
This guide shows two ways to run the bot: locally with Node.js or using Docker.
### Prerequisites
- Discord account with server admin permissions
- SourceXchange account
- Git
- Node.js 18+ and npm (for local run)
- Docker (for container run)
### Clone the repository
```bash
git clone https://github.com/KingIronMan2011/sourcexchange-sync-bot.git
cd sourcexchange-sync-bot
Copy the example env file and edit with your values:
cp .env.example .envRequired vars in .env:
DISCORD_TOKEN=
CLIENT_ID=
API_TOKEN=
PRODUCT_ID=
DISCORD_ROLE_ID=
NODE_ENV=production
npm installnpm startYou should see:
Logged in as YourBotName#1234
Slash commands deployed
Pull and run the prebuilt image:
docker pull kingjulian2011/sourcexchange-bot:latest
docker run --rm --env-file .env --name sourcexchange-bot kingjulian2011/sourcexchange-bot:latestdocker build -t sourcexchange-bot:local .
docker run --rm --env-file .env --name sourcexchange-bot sourcexchange-bot:localThe repository includes docker-compose.yml that uses the prebuilt image by default.
Start the service:
docker compose up -dRebuild (if you change Dockerfile or want a local build):
docker compose build
docker compose up -dA GitHub Actions workflow builds and pushes images to Docker Hub and GHCR on push and workflow_dispatch. Add these repo secrets to enable Docker Hub pushes:
- DOCKER_USERNAME
- DOCKER_PASSWORD
GHCR uses the repository GITHUB_TOKEN by default.
- Go to the Discord Developer Portal → New Application.
- Save the Application ID as
CLIENT_ID. - Create a Bot user and copy the bot token →
DISCORD_TOKEN. - Enable Server Members Intent under Bot settings if required.
- OAuth2 → URL Generator
- Select scopes:
bot,applications.commands - Select permissions:
Send Messages,Use Slash Commands,Manage Roles - Open generated URL and invite to your server.
- Product ID: check your product URL / seller dashboard on SourceXchange.
- Discord Role ID: enable Developer Mode → right-click role → Copy ID.
Keep secrets out of source. Use repository secrets for CI and .env for local runs. Example .env.example is provided.
- Check logs:
- Docker:
docker logs -f sourcexchange-bot - Local: console output from
npm start
- Docker:
- Verify env values and that the bot has Manage Roles and required intents.
PM2 example:
npm install -g pm2
pm2 start bot.ts --name sourcexchange-bot --interpreter node
pm2 save
pm2 startupCreate a systemd unit to run the container or pm2 service (not included here).
- Do not upgrade global npm inside images unless pinned to a verified patched version.
- Keep dependencies and base images up to date and commit lockfiles.
- See repository docs for Configuration, User Guide and Troubleshooting.