Skip to content

Discord Bots

Integrate abystrixLicense into your Discord bot to validate licenses and protect your bot from unauthorized use.

Prerequisites

  • Node.js environment (for Discord.js)
  • Your Discord bot project
  • abystrixLicense API credentials (API token from Settings > API Tokens)

Integration Steps

1. Install Required Packages

bash
npm install axios dotenv

2. Create License Validator

javascript
const axios = require('axios');
require('dotenv').config();

class LicenseValidator {
    constructor(licenseKey, productId) {
        this.licenseKey = licenseKey;
        this.productId = productId;
        this.apiUrl = 'https://your-server.com/api/v1/validate';
    }

    async validateLicense() {
        try {
            const response = await axios.post(this.apiUrl, {
                licenseKey: this.licenseKey,
                productId: this.productId,
                hwid: process.env.HWID || 'discord-bot',
                productVersion: '1.0.0'
            });

            return response.status === 200;
        } catch (error) {
            console.error('License validation failed:', error.message);
            return false;
        }
    }
}

module.exports = LicenseValidator;

3. Implement in Bot

javascript
const { Client, GatewayIntentBits } = require('discord.js');
const LicenseValidator = require('./LicenseValidator');

const client = new Client({ 
    intents: [GatewayIntentBits.Guilds] 
});

const licenseValidator = new LicenseValidator(
    process.env.LICENSE_KEY, 
    parseInt(process.env.PRODUCT_ID)
);

client.once('ready', async () => {
    const isValid = await licenseValidator.validateLicense();
    if (!isValid) {
        console.error('Invalid license - Bot shutting down');
        client.destroy();
        process.exit(1);
    }
    console.log('Bot is ready! License validated.');
});

// Periodic validation (every 24 hours)
setInterval(async () => {
    const isValid = await licenseValidator.validateLicense();
    if (!isValid) {
        console.error('License validation failed - Bot shutting down');
        client.destroy();
        process.exit(1);
    }
}, 24 * 60 * 60 * 1000);

client.login(process.env.DISCORD_BOT_TOKEN);

4. Environment Configuration

env
# .env file
DISCORD_BOT_TOKEN=your-discord-bot-token
LICENSE_KEY=XXXXX-XXXXX-XXXXX-XXXXX
PRODUCT_ID=1
HWID=my-discord-bot

Best Practices

  1. Startup Validation

    • Validate before bot initialization
    • Implement graceful shutdown on failure
    • Clear error logging for debugging
  2. Periodic Validation

    • Run validation every 24 hours
    • Handle network timeouts gracefully
    • Log validation attempts for monitoring
  3. Security

    • Store license key in environment variables
    • Never hardcode credentials in source code
    • Use .env files or secret management

Using API v2 (Advanced)

For more control, use the API v2 token-based authentication:

javascript
const axios = require('axios');

class LicenseManager {
    constructor(apiToken) {
        this.apiToken = apiToken;
        this.baseUrl = 'https://your-server.com/api/v2';
    }

    async getLicense(licenseKey) {
        try {
            const response = await axios.get(
                `${this.baseUrl}/licenses/by-license-key/${licenseKey}`,
                { headers: { TOKEN: this.apiToken } }
            );
            return response.data;
        } catch (error) {
            return null;
        }
    }

    async listLicenses() {
        try {
            const response = await axios.get(
                `${this.baseUrl}/licenses`,
                { headers: { TOKEN: this.apiToken } }
            );
            return response.data;
        } catch (error) {
            return [];
        }
    }
}

Common Issues

  1. Validation Failures

    • Check license key validity in the admin dashboard
    • Verify network connectivity to the API server
    • Confirm the product ID matches your product
  2. Runtime Issues

    • Monitor bot logs for validation errors
    • Check for API rate limits (configurable in settings)
    • Verify license status is not expired or deactivated

Released under the MIT License.