💥 Apliko: A TypeScript Discord.js framework

Related tags

Video/Audio Apliko
Overview

💥 Apliko: A TypeScript Discord.js framework

Apliko is a Discord.js framework aimed at making the work of professionals easier and faster. It uses a collection of applications to accomplish common tasks in Discord bots. These include slash commands, channel controllers, questionnaires, and panels.

Documentation

GitBook Docs

Todo:

  • Finish rewriting interactions so you can send responses using class members instead of global util functions
  • Compare commands to existing commands so they don't edit if none are needed, removing the 'this command is outdated' error
  • Clean up codebase, looks like 7 people coming from 7 different backgrounds have been working on this lmao

Use Apliko in your project

Apliko has not yet been published to NPM so you'll have to add a file dependency. Simply clone this repository into a new folder, and add this line to your depdendencies in package.json

"apliko": "file:path/to/Apliko"

Getting Started

Here's some code to get your simple bot up and running

import { AplikoBot } from 'apliko';

const bot = new AplikoBot(
    intents: [
        Intents.FLAGS.GUILDS,
        Intents.FLAGS.GUILD_MEMBERS,
        Intents.FLAGS.GUILD_MESSAGES,
        Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
        Intents.FLAGS.GUILD_VOICE_STATES,
    ],
    token: '
   
    '
   
);

bot.client.on('ready', async () => {
    // Do something
});

bot.login();

Simple enough, right? Well you may find yourself in a situation where you'd like to add some properties in the AplikoBot class since it gets passed as a parameter to all other Apliko classes like: a connection to a database, a websocket connection, or maybe a payment gateway. While there's many ways to go about adding these properties I recommend using basic class inheritance to mix your properties into existing Apliko classes. Here's an example of a slash command using my own AplikoBot class.

export class InheritBot extends AplikoBot {

    private _database: Database;

    public constructor() {
        super(
            intents: [
                Intents.FLAGS.GUILDS,
                Intents.FLAGS.GUILD_MEMBERS,
                Intents.FLAGS.GUILD_MESSAGES,
                Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
                Intents.FLAGS.GUILD_VOICE_STATES,
            ],
            token: 'YOUR_BOT_TOKEN'
        );

        this._database = new Database();
        this.commands.registerCommands(new MySlashCommand(this));
    }

    public get database() {
        return this._database;
    }

}

export class InheritSlashCommand extends SlashCommand {

    private _myBot: InheritBot;

    constructor(myBot: InheritBot) {
        super(myBot); // Pass myBot to the SlashCommand constructor since it extends AplikoBot
        this._myBot = myBot; // Store myBot in a separate variable so we save the types
    }

    // Override the getter for AplikoBot to return InheritBot instead
    override get bot(): MyBot {
        return this._myBot
    }

}

@DefineCommand
@NameCommand('rnchannel')
@DescribeCommand('Rename a channel')
export class MySlashCommand extends InheritSlashCommand {

    // channel and newName command options are automatically detected, more on that later ;)
    @CommandExecutor
    public async execute(interaction: CommandInteraction, channel: TextChannel, newName: string) {
        // Rename the channel...
    }

}

Global Interaction Handlers

Creating a global interaction handler means you'll recieve all interactionCreate events. It's recommended for components that can exist in multiple places at the same time. To create a global interaction handler, you have to extend the InteractionHandler class and decorate your functions as callbacks.

@RegisterCallbacks
export class MyInteractionHandler extends InteractionHandler {
  @ButtonCallback("my_button_id")
  public async handleMyButton(context: ButtonInteractionContext) {
    //context.interaction...
  }
}

You probably noticed that interactions are stored in a context. That's because Apliko enables you to persist data alongside a component id. This makes doing cool things like invite components that never expire and persist across restarts incredibly easy to make.

This works by using an on-disk nosql database to store the real component id and data along with a uniquely generated string. That string replaces the components id when it's sent to the Discord API so that when a component interaction with that string is receieved, we can retrieve the real component id and attached data to pass along to the corresponding callback.

    @ButtonCallback('my_button_id')
    public async handleMyButton(context: ButtonInteractionContext) {
        await context.interaction.reply({
            content: 'Click yes to accept',
            components: ComponentsToDJS(
                ActionRow
                    .new()
                    .components(
                        Button
                            .new()
                            .label('Yes')
                            .style(ButtonStyle.SUCCESS)
                            .id(CreateComponentInteractionData({
                                componentId: 'accept_invite',
                                data: [
                                    channelId: context.interaction.channelId
                                ]
                            })))
            )
        })
    }

    @ButtonCallback('accept_invite')
    public async handleAcceptInvite(context: ButtonInteractionContext) {
        const channelId = context.data.data[0] // I need to refactor this, I know lol
        // add to channel based on id.....
    }

Modals

Sending modals in Apliko is just as quick and easy as the rest of its features. To send a modal you use the function InteractionReplyModal as shown below.

@ButtonCallback('my_form_button')
public async openMyForm(context: ButtonInteractionContext) {
    await InteractionReplyModal(this.bot, context.interaction, // this.bot contains the REST instance
        Modal
            .new()
            .id('my_form')
            .title('My Form')
            .components(
                TextField
                    .new()
                    .customId('my_form_field')
                    .title('Field')
                    .placeholder('This is placeholder text!')
                    .style(TextFieldStyle.SHORT))
    );
}

Recieving modals makes use of our collector class. Just like collecting message components or messages, all you have to do is pass a key so Apliko can determine if the modal submited is the one your waiting for.

//public async openMyForm(context:...
const formResponses = await this.bot.collector.collectForm({
  userId: context.interaction.user.id,
  channelId: context.interaction.channelId,
  modalId: "my_form",
});
You might also like...

Tutoriel en francais sur le framework Sheweny, création de bots discord pour les débutants

Tutoriel Sheweny ✨ Sheweny est un framework pour créer des bots sur discord avec discord.js. Bienvenue dans le repo du tutoriel sur le framework Shewe

Jul 29, 2022

A complete framework to make a leveling system using discord.js v13

Discord Easy Leveling A complete framework to make a leveling system using discord.js v13 Why discord-easy-leveling? ✨ Beginner friendly ✍ Full custom

Sep 12, 2022

⚡ Discord bot with economy, gambling, music, fun, moderation features based on discord.js v12

⚡ Discord bot with economy, gambling, music, fun, moderation features based on discord.js v12

Crucian Crucian is my discord bot with simple structure based on discord.js Click Here to invite Crucian to your server Author Crucian © Apoo Authored

Jul 26, 2021

A multipurpose Discord-bot created using discord.js.

Flame A multipurpose Discord-bot with music, economy, utils, and also auto-moderation. Flame is a powerfull, multipurpose and fully modular Discord-bo

Nov 14, 2021

An simple package to create an Activity in Discord Voice Channel using Discord.js

An simple package to create an Activity in Discord Voice Channel using Discord.js

discordjs-activity An simple package to create an Activity in Discord Voice Channel using Discord.js 📂 | Installation npm install discordjs-activity

Nov 15, 2022

best discord selfbot with discord.js-selfbot npm

Discord-Afk-Selfbot best discord selfbot with discord.js-selfbot npm How to start the Bot step by step : Step 1 === Open a CMD the npm init step 2 ==

Aug 18, 2022

Cyrus is a Discord Bot with focus on Fun, Moderation, information and much more commands! Made it with Discord.js

Cyrus is a Discord Bot with focus on Fun, Moderation, information and much more commands! Made it with Discord.js

Cyrus Cyrus is a Discord Bot with focus on Fun, Moderation, information and much more commands! Made it with Discord.js Invite : Click here Vote : Top

Dec 3, 2022

OptiBOT - My discord.js V13 discord bot.

OptiBOT Just a discord.js v13 bot for my discord server. if you plan to use this bot for your server, dont. This i made this bot just for learning js

Jan 3, 2022

A discord bot using @discord.js and mongoose. Used for music, moderation, and entertainment.

hazel A discord bot using @discord.js and mongoose. Used for music, moderation, and entertainment. Features Music ― supporting YouTube, Spotify and So

Dec 31, 2022
Owner
Anthony A.
Software freelancer specializing in Discord related projects
Anthony A.
A simple & easy2use API for obtaining information about a discord user, discord bot or discord guild and their use for some purpose on websites!

discord-web-api A simple & easy2use API for obtaining information about a discord user, discord bot or discord guild and their use for some purpose on

InvalidLenni 2 Jun 28, 2022
Discord-Bot - You can use the discord bot codes that are updated in every video of the codes I use in the discord bot making series that I have published on my youtube channel.

Discord-Bot You can use the discord bot codes that are updated in every video of the codes I use in the discord bot making series that I have publishe

Umut Bayraktar 114 Jan 3, 2023
Gitlift Discord Bot is a discord bot which is listening Discord Messages to reply with user gitlift profile and total contributions.

Remoklify - Gitlift Discord Bot Gitlift Discord Bot is a discord bot which is listening Discord Messages to reply with user gitlift profile and total

Remoklify 3 Mar 20, 2022
A discord bot made using discord.js and discord-player

Musx A custom discord bot that can play music in your server ?? Add the bot to your server If you are looking for a music bot for your Discord server

Shashwat Singh 4 Mar 28, 2022
About Discord bot draft that does not contain ready-made commands, compatible with discord.js v14. Create your own discord bot with this command handler.

discordJS-V14 About Discord bot draft that does not contain ready-made commands, compatible with discord.js v14. Create your own discord bot with this

Umut Bayraktar 36 Dec 28, 2022
Discord.JTS - Slash Commands for Discord.JS 13 using Typescript

Installation Requirements and Recommendations: Node.js Git Visual Studo Code An empty test Discord server Step 0: Login into Discord in the Browser Go

null 1 Jan 13, 2022
Denky is a multipurpose Discord bot, build with Node.js, TypeScript and discord.js.

?? Denky Bot Denky is a brazilian Discord bot, build with Node.js, TypeScript and discord.js. ⚙️ How to Create a Discord application. Guide Install No

Davi Patricio 8 Apr 6, 2022
Denky is a multipurpose Discord bot used in +3000 servers. Built with Node.js, TypeScript and discord.js.

?? Denky Bot Denky is a brazilian Discord bot, built with Node.js, TypeScript and discord.js. ⚙️ Self hosting ⚠️ Support will not be provided for self

Denky Labs 19 Dec 26, 2022
Eclipse is a multipurpose Discord bot. Built with Node.js, TypeScript and discord.js.

?? Eclipse Bot Eclipse is a brazilian Discord bot, built with Node.js, TypeScript and discord.js. ?? Self-Hosting ⚠️ Support will not be provided for

Eclipse labs 14 Dec 15, 2022
An open-source Discord bot built with Discord.JS & TypeScript

?? Hans - Discord Bot Discord Bot build with Discord.JS, TypeScript, and lots of ❤️ Invite hans to your server You can invite the bot here ?? . It's u

Sorin 9 Nov 15, 2022