Files
bot.js
package.json
Code
2 133
bot.js
const { Client, EmbedBuilder, GatewayIntentBits, SlashCommandBuilder } = require('discord.js');
require('dotenv').config();
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const portmodCommand = new SlashCommandBuilder()
.setName('portmod')
.setDescription('Get a step-by-step guide to porting a Java mod to a Bedrock addon.')
.addAttachmentOption(option =>
option
.setName('jar')
.setDescription('The Minecraft Java Edition mod JAR to review while planning a port.')
.setRequired(true)
);
const guideEmbeds = [
new EmbedBuilder()
.setColor(0x45b86b)
.setTitle('Java mod β Bedrock addon: porting guide')
.setDescription(
'**Important:** this command does not transform the uploaded JAR or produce an `.mcaddon`. Java mods and Bedrock add-ons use different engines, APIs, and formats; arbitrary Java code cannot be reliably translated automatically. Use the JAR as a reference and rebuild its features for Bedrock.
' +
'**1. Understand the differences**\n' +
'Java mods run on Java Edition through loaders such as Fabric, Forge, or NeoForge and can use Java code and loader APIs. Bedrock add-ons use behavior packs and resource packs, JSON data, assets, and (where supported) the Bedrock Script API. Some features have no Bedrock equivalent.\n\n' +
'**2. Extract and inspect the JAR**\n' +
'Make a backup, then open the `.jar` with 7-Zip or WinRAR (a JAR is ZIP-based). Inspect `fabric.mod.json`, `META-INF/mods.toml`, or `mcmod.info` for loader and version details, plus assets, recipes, loot tables, tags, and configuration files. Decompiled Java may help explain behavior, but do not assume it can be reused as Bedrock code.\n\n' +
'**3. Make a feature map**\n' +
'List each feature and its required assets or logic. Map items, blocks, entities, recipes, and loot to Bedrock data/resource-pack capabilities where possible. Rewrite supported gameplay logic with the Bedrock Script API. Rendering hooks, custom loaders, arbitrary Java libraries, and some advanced mechanics may need a redesign or may not be portable. Check current Bedrock documentation for API and version support.'
),
new EmbedBuilder()
.setColor(0x45b86b)
.setTitle('Build and package the add-on')
.setDescription(
'**4. Create the pack folders**\n' +
'Keep behavior and resources in separate packs when both are needed. Replace the example names and UUIDs with your own values.\n' +
'```text\n' +
'MyAddon/\n' +
'βββ behavior_packs/MyAddon_BP/\n' +
'β βββ manifest.json\n' +
'β βββ scripts/ (optional)\n' +
'βββ resource_packs/MyAddon_RP/\n' +
' βββ manifest.json\n' +
' βββ textures/\n' +
' βββ models/ (as needed)\n' +
'```\n' +
'**5. Add a behavior-pack manifest**\n' +
'Generate a unique UUID for each pack and module. Keep the version as three integers. The resource pack needs its own manifest and UUIDs; add a dependency on the behavior pack UUID when the packs depend on each other.\n' +
'```json\n' +
'{\n' +
' "format_version": 2,\n' +
' "header": { "name": "[Name] BP", "description": "[Description]", "uuid": "[UUID]", "version": [1, 0, 0], "min_engine_version": [1, 20, 0] },\n' +
' "modules": [{ "type": "data", "uuid": "[UUID]", "version": [1, 0, 0] }]\n' +
'}\n' +
'```\n' +
'Use real UUIDs in place of each `[UUID]`; do not reuse a UUID between header and module or between packs. Set `min_engine_version` and any Script API dependencies to versions supported by your target Bedrock release.'
),
new EmbedBuilder()
.setColor(0x45b86b)
.setTitle('Test and install')
.setDescription(
'**6. Rebuild assets and scripts**\n' +
'Recreate textures and models in Bedrock-compatible formats and paths. Implement only supported behavior using Bedrock JSON and the Script API; consult the official Bedrock Creator documentation for schemas, APIs, and version requirements. Do not copy Java classes into the pack.\n\n' +
'**7. Package as `.mcaddon`**\n' +
'Put `behavior_packs/` and `resource_packs/` at the archive root, compress those folders as a ZIP, then rename the ZIP extension to `.mcaddon`. Check that the archive does not contain an extra enclosing folder level.\n\n' +
'**8. Import and test**\n' +
'Open the `.mcaddon` with Minecraft Bedrock to import it. In the target worldβs settings, enable the behavior pack and resource pack under **Add-Ons / Packs**, then test each feature in a backup world. Review the content log and fix manifest, asset, or script errors.\n\n' +
'A successful port is a new Bedrock implementation, not a converted copy of the Java mod.'
)
];
client.once('clientReady', async () => {
try {
await client.application.commands.set([portmodCommand]);
console.log(`Bot is ready! Logged in as ${client.user.tag}`);
console.log('KODARI_READY');
} catch (error) {
console.error('Failed to register slash commands:', error);
}
});
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand() || interaction.commandName !== 'portmod') return;
const attachment = interaction.options.getAttachment('jar', true);
if (!attachment.name.toLowerCase().endsWith('.jar')) {
await interaction.reply({
content: 'Please attach a Minecraft Java mod file with a `.jar` extension. This command provides a porting guide; it does not convert the file.',
ephemeral: true
});
return;
}
try {
await interaction.reply({
content: `Guide for **${attachment.name}** (the JAR is not automatically converted):`,
embeds: guideEmbeds,
ephemeral: true
});
} catch (error) {
console.error('Failed to send the /portmod guide:', error);
if (interaction.deferred || interaction.replied) {
await interaction.followUp({ content: 'I could not send the guide. Please try again.', ephemeral: true }).catch(console.error);
} else {
await interaction.reply({ content: 'I could not send the guide. Please try again.', ephemeral: true }).catch(console.error);
}
}
});
client.on('error', error => console.error('Discord client error:', error));
process.on('unhandledRejection', error => console.error('Unhandled promise rejection:', error));
if (!process.env.DISCORD_TOKEN) {
throw new Error('DISCORD_TOKEN is missing. Add it to the .env file before starting the bot.');
}
client.login(process.env.DISCORD_TOKEN).catch(error => {
console.error('Failed to log in to Discord:', error);
process.exitCode = 1;
});