1.0.2 • Published 5 months ago

discord-auto-mc-versions v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

Discord Auto MC Versions

discord-auto-mc-versions is a lightweight Node.js module designed specifically for Discord.js applications. It retrieves and tracks Minecraft Bedrock Linux version data (stable and preview) from a GitHub raw URL and provides utilities to integrate this data into Discord bots. The module is ideal for bot developers who want to monitor and display version updates in their Discord servers or direct messages.

Functions

The module exports the following functions:

  • getVersions(): Returns the default versions (stable and preview) embedded in the module during build time.
  • getStable(): Returns the default stable version.
  • getPreview(): Returns the default preview version.
  • fetchVersions(): Fetches the latest versions from the GitHub raw URL asynchronously.
  • loadVersionsFromFile(filePath): Loads versions from a custom JSON file provided by the user.
  • checkForUpdates(oldVersions): Compares old versions with the latest versions from GitHub and returns updates if any.

Features

  • Real-time Version Fetching: Retrieve the latest Minecraft Bedrock Linux versions from GitHub.
  • Custom JSON Support: Load version data from a user-defined JSON file.
  • Update Detection: Detect changes between versions with detailed update information (old vs. new).
  • Discord.js Focused: Designed to seamlessly integrate with Discord.js bots, providing raw data for custom embeds or messages.
  • Lightweight: Minimal dependencies and simple API for easy use.

Installation

Install the module via npm:

 npm install discord-auto-mc-versions

Usage/Examples

1. Using with Embed

This example shows how to use the module to fetch versions and display them in a Discord embed.

const { Client, GatewayIntentBits, EmbedBuilder } = require('discord.js');
const bdsVersions = require('discord-auto-mc-versions');

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

client.once('ready', () => {
  console.log('Bot is ready!');
});

client.on('messageCreate', async (message) => {
  if (message.author.bot) return;

  if (message.content === '!versions') {
    const versions = await bdsVersions.fetchVersions();

    const embed = new EmbedBuilder()
      .setTitle('Minecraft Bedrock Linux Versions')
      .addFields(
        { name: 'Stable', value: `\`\`\`${versions.versions.stable}\`\`\``, inline: false },
        { name: 'Preview', value: `\`\`\`${versions.versions.preview}\`\`\``, inline: false }
      )
      .setColor('#00f529')
      .setTimestamp();

    await message.channel.send({ embeds: [embed] });
  }

  if (message.content === '!check-updates') {
    const currentVersions = bdsVersions.getVersions();
    const update = await bdsVersions.checkForUpdates(currentVersions);

    if (update) {
      const { updates } = update;
      const embed = new EmbedBuilder()
        .setTitle('Version Updates')
        .setColor('#90EE90')
        .setTimestamp();

      updates.forEach(update => {
        embed.addFields({
          name: `${update.type} Updated`,
          value: `\`\`\`${update.oldVersion} -> ${update.newVersion}\`\`\``,
          inline: false
        });
      });

      await message.channel.send({ embeds: [embed] });
    } else {
      await message.reply('No updates available.');
    }
  }
});

client.login('YOUR_BOT_TOKEN');

2. Using without Embed

This example demonstrates how to use the module to send version data as plain text.

const { Client, GatewayIntentBits } = require('discord.js');
const bdsVersions = require('discord-auto-mc-versions');

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

client.once('ready', () => {
  console.log('Bot is ready!');
});

client.on('messageCreate', async (message) => {
  if (message.author.bot) return;

  if (message.content === '!versions') {
    const versions = await bdsVersions.fetchVersions();
    const reply = `Stable: ${versions.versions.stable}\nPreview: ${versions.versions.preview}`;
    await message.reply(reply);
  }

  if (message.content === '!check-updates') {
    const currentVersions = bdsVersions.getVersions();
    const update = await bdsVersions.checkForUpdates(currentVersions);

    if (update) {
      const { updates } = update;
      let reply = 'Updates:\n';
      updates.forEach(update => {
        reply += `${update.type}: ${update.oldVersion} -> ${update.newVersion}\n`;
      });
      await message.reply(reply);
    } else {
      await message.reply('No updates available.');
    }
  }
});

client.login('YOUR_BOT_TOKEN');
1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago