Files
commands
events
.gitignore
config.json
index.js
package.json
README.md
Code
8 1,152
index.js
// ==============================================================
// 🎫 DISCORD TICKET BOT + MINECRAFT CHAT BRIDGE
// ==============================================================
const { Client, GatewayIntentBits, Collection, EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder, ButtonBuilder, ButtonStyle, SlashCommandBuilder, REST, Routes, PermissionFlagsBits, ChannelType, WebhookClient } = require('discord.js');
const express = require('express');
const { Rcon } = require('rcon-client');
// ======================= CONFIG =======================
// WKLEJ SWOJE WARTOSCI PONIZEJ:
const TOKEN = "TOKEN"; // ← WKLEJ TOKEN BOTA
const CLIENT_ID = "1492839109037920427"; // ← ID APLIKACJI BOTA
const GUILD_ID = "1264335386537099265"; // ← ID SERWERA DISCORD
const SUPPORT_ROLE_ID = "1421880497138569387"; // ← ID ROLI SUPPORT
const CHAT_CHANNEL_ID = "1492987160893329489"; // ← ID KANALU CHAT MC<->DC
// MINECRAFT RCON CONFIG
const MC_RCON_HOST = "localhost"; // ← IP SERWERA MC
const MC_RCON_PORT = 25575; // ← PORT RCON (domyslnie 25575)
const MC_RCON_PASSWORD = "your_rcon_password"; // ← HASLO RCON Z server.properties
// WEBHOOK SERVER PORT (do odbierania wiadomosci z MC)
const WEBHOOK_PORT = 3000; // ← PORT SERWERA WEBHOOK
// ======================================================
const config = require('./config.json');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers
]
});
client.cooldowns = new Collection();
client.activeTickets = new Map();
// RCON Connection
let rconClient = null;
// Express server for MC webhooks
const app = express();
app.use(express.json());
// ==================== READY EVENT ====================
client.once('ready', async () => {
console.log(`✅ ʙᴏᴛ ᴊᴇsᴛ ɢᴏᴛᴏᴡʏ! ${client.user.tag}`);
// Connect to MC RCON
try {
rconClient = await Rcon.connect({
host: MC_RCON_HOST,
port: MC_RCON_PORT,
password: MC_RCON_PASSWORD
});
console.log('✅ ᴘᴏʟᴀᴄᴢᴏɴᴏ ᴢ ᴍɪɴᴇᴄʀᴀғᴛ ʀᴄᴏɴ');
} catch (error) {
console.error('❌ ʙʟᴀᴅ ᴘᴏʟᴀᴄᴢᴇɴɪᴀ ʀᴄᴏɴ:', error.message);
}
const commands = [
new SlashCommandBuilder()
.setName('setup')
.setDescription('sᴇᴛᴜᴘ ᴛɪᴄᴋᴇᴛ ᴘᴀɴᴇʟ')
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
];
const rest = new REST({ version: '10' }).setToken(TOKEN);
try {
console.log('🔄 ʀᴇᴊᴇsᴛʀᴀᴄᴊᴀ ᴋᴏᴍᴇɴᴅ...');
await rest.put(
Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID),
{ body: commands }
);
console.log('✅ ᴋᴏᴍᴇɴᴅʏ ᴢᴀʀᴇᴊᴇsᴛʀᴏᴡᴀɴᴇ');
} catch (error) {
console.error('❌ ʙʟᴀᴅ ʀᴇᴊᴇsᴛʀᴀᴄᴊɪ ᴋᴏᴍᴇɴᴅ:', error);
}
client.user.setActivity('ᴛɪᴄᴋᴇᴛ sʏsᴛᴇᴍ 🎫', { type: 3 });
});
// ==================== INTERACTION CREATE EVENT ====================
client.on('interactionCreate', async (interaction) => {
if (interaction.isChatInputCommand()) {
if (interaction.commandName === 'setup') {
await handleSetupCommand(interaction);
}
} else if (interaction.isStringSelectMenu()) {
if (interaction.customId === 'ticket_category') {
await handleTicketCreation(interaction);
}
} else if (interaction.isButton()) {
if (interaction.customId === 'close_ticket') {
await handleCloseTicket(interaction);
} else if (interaction.customId === 'claim_ticket') {
await handleClaimTicket(interaction);
} else if (interaction.customId === 'add_user') {
await handleAddUser(interaction);
}
}
});
// ==================== MC <-> DC CHAT BRIDGE ====================
// DC -> MC
client.on('messageCreate', async (message) => {
if (message.author.bot) return;
if (message.channel.id !== CHAT_CHANNEL_ID) return;
const username = message.member?.displayName || message.author.username;
const content = message.content;
if (!rconClient) {
console.error('❌ ʀᴄᴏɴ ɴɪᴇ ᴘᴏʟᴀᴄᴢᴏɴʏ');
return;
}
try {
// Escape quotes in message
const escaped = content.replace(/"/g, '\\"');
// Send to MC using tellraw
const command = `tellraw @a ["",{"text":"[","color":"dark_gray"},{"text":"DC","color":"#5865F2","bold":true},{"text":"] ","color":"dark_gray"},{"text":"${username}","color":"white"},{"text":": ","color":"gray"},{"text":"${escaped}","color":"white"}]`;
await rconClient.send(command);
} catch (error) {
console.error('❌ ʙʟᴀᴅ ᴡʏsʏʟᴀɴɪᴀ ᴅᴏ ᴍᴄ:', error.message);
}
});
// MC -> DC (webhook endpoint)
app.post('/minecraft-chat', async (req, res) => {
try {
const { player, message, prefix } = req.body;
if (!player || !message) {
return res.status(400).json({ error: 'ʙʀᴀᴋ ᴅᴀɴʏᴄʜ' });
}
const channel = client.channels.cache.get(CHAT_CHANNEL_ID);
if (!channel) {
return res.status(404).json({ error: 'ᴋᴀɴᴀʟ ɴɪᴇ ᴢɴᴀʟᴇᴢɪᴏɴʏ' });
}
// Format message with LuckyPerms prefix if available
let formattedMessage;
if (prefix) {
formattedMessage = `**[MC]** ${prefix} **${player}**: ${message}`;
} else {
formattedMessage = `**[MC]** **${player}**: ${message}`;
}
await channel.send(formattedMessage);
res.status(200).json({ success: true });
} catch (error) {
console.error('❌ ʙʟᴀᴅ ᴡᴇʙʜᴏᴏᴋᴀ:', error);
res.status(500).json({ error: 'ʙʟᴀᴅ sᴇʀᴡᴇʀᴀ' });
}
});
// Start webhook server
app.listen(WEBHOOK_PORT, () => {
console.log(`✅ ᴡᴇʙʜᴏᴏᴋ sᴇʀᴡᴇʀ: ᴘᴏʀᴛ ${WEBHOOK_PORT}`);
});
// ==================== SETUP COMMAND ====================
async function handleSetupCommand(interaction) {
const { cooldowns } = client;
const cooldownKey = 'setup';
if (!cooldowns.has(cooldownKey)) {
cooldowns.set(cooldownKey, new Map());
}
const now = Date.now();
const timestamps = cooldowns.get(cooldownKey);
const cooldownAmount = 5 * 1000;
if (timestamps.has(interaction.user.id)) {
const expirationTime = timestamps.get(interaction.user.id) + cooldownAmount;
if (now < expirationTime) {
const timeLeft = (expirationTime - now) / 1000;
return interaction.reply({
content: `⏰ ᴘᴏᴄᴢᴇᴋᴀᴊ ${timeLeft.toFixed(1)}s ᴘʀᴢᴇᴅ ᴜᴢʏᴄɪᴇᴍ ᴛᴇᴊ ᴋᴏᴍᴇɴᴅʏ`,
ephemeral: true
});
}
}
timestamps.set(interaction.user.id, now);