Discord Bots
Integrate abystrixLicense into your Discord bot (JDA, Discord.js, Discord.py) for automated license management.
JDA (Java)
java
public class LicenseCommand extends SlashCommand {
public LicenseCommand() {
setName("license");
setDescription("Validate your license key");
addOption(OptionType.STRING, "key", "Your license key", true);
}
@Override
public void execute(SlashCommandEvent event) {
String key = event.getOption("key").getAsString();
String discordId = event.getUser().getId();
// Validate via API v2
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://your-server.com/api/v2/licenses/by-license-key/" + key))
.header("TOKEN", "your-api-token")
.GET()
.build();
HttpClient.newHttpClient().sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenAccept(response -> {
if (response.statusCode() == 200) {
event.reply("License is valid! ✅").setEphemeral(true).queue();
} else {
event.reply("Invalid or expired license ❌").setEphemeral(true).queue();
}
});
}
}Discord.js (Node.js)
javascript
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('license')
.setDescription('Validate your license key')
.addStringOption(option =>
option.setName('key').setDescription('Your license key').setRequired(true)),
async execute(interaction) {
const key = interaction.options.getString('key');
const response = await fetch(`https://your-server.com/api/v2/licenses/by-license-key/${key}`, {
headers: { 'TOKEN': 'your-api-token' }
});
if (response.ok) {
await interaction.reply({ content: 'License is valid! ✅', ephemeral: true });
} else {
await interaction.reply({ content: 'Invalid or expired license ❌', ephemeral: true });
}
},
};Discord.py (Python)
python
import aiohttp
import discord
from discord.ext import commands
class License(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.api_token = "your-api-token"
self.base_url = "https://your-server.com"
@discord.app_commands.command(name="license", description="Validate your license key")
async def license(self, interaction: discord.Interaction, key: str):
async with aiohttp.ClientSession() as session:
headers = {"TOKEN": self.api_token}
async with session.get(
f"{self.base_url}/api/v2/licenses/by-license-key/{key}",
headers=headers
) as resp:
if resp.status == 200:
await interaction.response.send_message("License is valid! ✅", ephemeral=True)
else:
await interaction.response.send_message("Invalid or expired license ❌", ephemeral=True)