Files
.gitignore
bot.js
config.json
database.js
package.json
queueManager.js
README.md
Code
7 825
bot.js
const { Client, GatewayIntentBits, Collection, Events, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder, EmbedBuilder, PermissionFlagsBits, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder } = require('discord.js');
const { SlashCommandBuilder } = require('discord.js');
require('dotenv').config();
const axios = require('axios');
const config = require('./config.json');
const database = require('./database');
const queueManager = require('./queueManager');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers
]
});
database.initDatabase();
client.once(Events.ClientReady, async () => {
console.log(`✅ Bot is ready! Logged in as ${client.user.tag}`);
const commands = [
new SlashCommandBuilder()
.setName('queue')
.setDescription('Manage the testing queue')
.addSubcommand(subcommand =>
subcommand
.setName('open')
.setDescription('Open the testing queue')
)
.addSubcommand(subcommand =>
subcommand
.setName('close')
.setDescription('Close the current queue')
)
.addSubcommand(subcommand =>
subcommand
.setName('take')
.setDescription('Take the next player from the queue')
),
new SlashCommandBuilder()
.setName('verify')
.setDescription('Post the verification message with button'),
new SlashCommandBuilder()
.setName('result')
.setDescription('Post a test result')
.addUserOption(option =>
option.setName('player')
.setDescription('The player who was tested')
.setRequired(true)
)
.addStringOption(option =>
option.setName('kit')
.setDescription('Testing kit used')
.setRequired(true)
.addChoices(
...config.kits.map(kit => ({ name: kit, value: kit }))
)
)
.addStringOption(option =>
option.setName('tier')
.setDescription('Tier achieved')
.setRequired(true)
.addChoices(
...config.tiers.map(tier => ({ name: tier, value: tier }))
)
)
.addStringOption(option =>
option.setName('evaluation')
.setDescription('Did the player earn an evaluation?')
.setRequired(true)
.addChoices(
{ name: 'Yes', value: 'Yes' },
{ name: 'No', value: 'No' }
)
),
new SlashCommandBuilder()
.setName('tests')
.setDescription('View tester statistics leaderboard'),
new SlashCommandBuilder()
.setName('resettests')
.setDescription('Reset all tester statistics (Staff only)')
];
try {
console.log('🔄 Registering slash commands...');
await client.application.commands.set(commands);
console.log('✅ Slash commands registered successfully');
} catch (error) {
console.error('❌ Error registering commands:', error);
}
});;
async function getMinecraftSkin(username) {
try {
const mojangResponse = await axios.get(`https://api.mojang.com/users/profiles/minecraft/${username}`, {
timeout: 5000
});
if (mojangResponse.data && mojangResponse.data.id) {
const uuid = mojangResponse.data.id;
return `https://render.crafty.gg/3d/bust/${uuid}`;
}
} catch (error) {
console.log(`Could not fetch UUID for ${username}, trying with username directly`);
}
return `https://render.crafty.gg/3d/bust/${username}`;
}
function hasTesterRole(member) {
return member.roles.cache.has(config.testerRoleId);
}
function hasStaffRole(member) {
return member.roles.cache.has(config.staffRoleId);
}
client.on(Events.InteractionCreate, async interaction => {
if (interaction.isChatInputCommand()) {
const { commandName } = interaction;
if (commandName === 'queue') {
if (!hasTesterRole(interaction.member)) {
return interaction.reply({ content: '❌ You do not have permission to use this command.', ephemeral: true });
}
const subcommand = interaction.options.getSubcommand();
if (subcommand === 'open') {
if (queueManager.isQueueOpen()) {
return interaction.reply({ content: '❌ A queue is already open. Close it first.', ephemeral: true });
}
const selectMenu = new StringSelectMenuBuilder()
.setCustomId('queue_kit_select')
.setPlaceholder('Select a testing kit')
.addOptions(
config.kits.map(kit => ({
label: kit,
value: kit,
emoji: '⚔️'
}))
);
const row = new ActionRowBuilder().addComponents(selectMenu);
const embed = new EmbedBuilder()
.setTitle('⚔️ Select Testing Kit')
.setDescription('Choose which kit this queue will be for:')
.setColor(config.colors.primary);
await interaction.reply({ embeds: [embed], components: [row], ephemeral: true });
}
if (subcommand === 'close') {
if (!queueManager.isQueueOpen()) {
return interaction.reply({ content: '❌ No queue is currently open.', ephemeral: true });
}
await queueManager.closeQueue();
await interaction.reply({ content: '✅ Queue has been closed.', ephemeral: true });
}
if (subcommand === 'take') {
if (!queueManager.isQueueOpen()) {
return interaction.reply({ content: '❌ No queue is currently open.', ephemeral: true });
}
const player = queueManager.takePlayer();
if (!player) {
return interaction.reply({ content: '❌ The queue is empty.', ephemeral: true });
}
await queueManager.updateQueueMessage(interaction.channel);
const embed = new EmbedBuilder()
.setTitle('🎯 Player Selected for Testing')
.setDescription(`**${player.tag}** has been taken from the queue for testing.`)
.setColor(config.colors.success)
.addFields(
{ name: '👤 Player', value: `<@${player.id}>`, inline: true }
)
.setTimestamp();
await interaction.reply({ embeds: [embed] });
}
}
if (commandName === 'verify') {
if (!hasTesterRole(interaction.member)) {
return interaction.reply({ content: '❌ You do not have permission to use this command.', ephemeral: true });
}