ZELTUXDocs Get ZELTUX

🧪 Addon Sample

#Your first addon is here! - Right below!

you’ll find a template addon designed to help you understand how everything works. It demonstrates the basic structure, including how to use commands and event

js
const chalk = require("chalk");
const utility = require("../modules/utils/utility");

const AddonData = {
    Name: 'TemplateAddon',
    Description: "Template addon for Zeltux bot",
    Developer: "TheDev",
    Discord: 'https://discord.gg/DuWnvynYtb'
};

const addonConfig = new utility.createAddonConfig(AddonData.Name, 'config.yml', {
    Permissions: {
        Template: ['everyone']
    },
    Colors: [
        "Green",
        "Blue",
        "Red",
        "Pink",
        "Orange"
    ]
}, { devMode: false });

const addonEmbed = new utility.createAddonConfig(AddonData.Name, 'lang.yml', {
    Reply: {
        title: "Hello, {user-username}",
        description: "This is our template addon, click on the magic button!",
        color: 'default',
        timestamp: true,
        buttons: [
            {
                customId: 'click_color',
                label: "Magic button",
                emoji: "🤭",
                style: 'secondary'
            }
        ]
    },
    Click: {
        title: "Oh, you clicked, your color is: `{color}`",
        color: 'default',
    }
}, { devMode: false });

const commands = [
    {
        name: 'template',
        description: "Template addon command",
        aliases: ['tem'],
        category: 'addon',
        options: [],
        async execute(mi, type, args, bot, send) {
            try {

                if (!utility.hasPerms(mi.member, mi.guild, addonConfig.Permissions.Template)) {
                    return send(type, mi, utility.builder({
                        ...bot.embeds.Permission,
                        variables: [
                            ...utility.userVariables(mi.member),
                            ...utility.serverVariables(mi.guild),
                            ...utility.botVariables(bot)
                        ]
                    }))
                }

                send(type, mi, utility.builder({
                    ...addonEmbed.Reply,
                    variables: [
                        ...utility.userVariables(mi.member),
                        ...utility.botVariables(bot),
                        ...utility.serverVariables(mi.guild),
                    ]
                }))

            } catch (err) {
                console.error(err);
                return send(type, mi, { content: '❌ Error occurred.' });
            }
        }
    }
];

const events = [
    {
        name: 'interactionCreate',
        customId: 'interaction-magic-button',
        once: false,
        async execute(interaction, bot) {
            if (!interaction.guild) return interaction.reply({ content: `You can run this only in the guild.` });
            if (interaction.isButton() && interaction.customId == addonEmbed.Reply.buttons[0].customId) {

                const colors = addonConfig.Colors;
                const chosen = colors[Math.floor(Math.random() * colors.length)]

                interaction.update(utility.builder({
                    ...addonEmbed.Click,
                    variables: [
                        ...utility.userVariables(interaction.member),
                        ...utility.botVariables(bot),
                        ...utility.serverVariables(interaction.guild),
                        { searchFor: /{color}/g, replaceWith: chosen }
                    ]
                }))
                return;
            }
        }
    }
];

module.exports = {
    name: AddonData.Name,
    description: AddonData.Description,
    developer: AddonData.Developer,
    discord: AddonData.Discord,
    commands: commands,
    events: events,
    onLoad(bot) { },
    onUnload(bot) { }
};