0.2.0 • Published 4 months ago

arcscord v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Arcscord

npm version Discord Shield

About

Arcscord is a project for simplify creating discord bot with typescript and also some utility package used by core package !

Install

pnpm add arcscord or npm install arcscord

Example

Command

// Command declaration
import { createCommand } from "arcscord";
import { EmbedBuilder } from "discord.js";

export const avatarCommand = createCommand({
  build: {
    slash: {
      name: "avatar",
      description: "test command",
      options: {
        user: {
          type: "user",
          description: "The user",
        },
        size: {
          type: "number",
          description: "yeah",
          choices: [
            512,
            {
              name: "1024 (default)",
              value: 1024,
            },
            2048,
          ],
        } as const,
      },
    },
    user: {
      name: "avatar",
    },
  },
  run: (ctx) => {
    const user = ctx.isSlashCommand
      ? ctx.options.user || ctx.user
      : ctx.targetUser;

    return ctx.reply({
      embeds: [
        new EmbedBuilder()
          .setTitle(`Avatar de ${user.displayName}`)
          .setImage(user.displayAvatarURL({
            size: ctx.isSlashCommand ? ctx.options.size || 1024 : 1024,
          }) || user.defaultAvatarURL),
      ],
      ephemeral: true,
    });
  },
});

// Command register
await client.loadCommands([avatarCommand]); // need be ready

Button

// declaration button
import { buildClickableButton, createButton } from "arcscord";

export const simpleButton = createButton({
  matcher: "simple_button",
  build: () => buildClickableButton({
    label: "Simple Button",
    style: "secondary",
    customId: "simple_button",
  }),
  run: (ctx) => {
    return ctx.reply("Clicked !");
  },
});

// usage
message.reply({
  components: [buildButtonActionRow(simpleButton.build())]
});

// register
client.loadComponents([simpleButton]);

Select Menu

// declaration
import { buildRoleSelectMenu, createSelectMenu } from "arcscord";
import { ComponentType } from "discord-api-types/v10";
import { EmbedBuilder } from "discord.js";

export const roleSelectMenu = createSelectMenu({
  type: ComponentType.RoleSelect,
  matcher: "role_select_menu",
  build: placeHolder => buildRoleSelectMenu({
    placeholder: placeHolder,
    customId: "role_select_menu",
    maxValues: 1,
    minValues: 1,
  }),
  run: (ctx) => {
    const role = ctx.values[0];

    return ctx.reply({
      embeds: [
        new EmbedBuilder()
          .setTitle(`Info about role ${role.name}`)
          .setDescription(`Position: ${role.position}\nColor: ${role.color}`)
          .setColor(role.color),
      ],
    });
  },
});

// usage
message.reply({
  components: [roleSelectMenu.build("Select a role")]
});

// register
client.loadComponents([roleSelectMenu]);

Modal

// declaration
import { buildModal, createModal } from "arcscord";

export const modal = createModal({
  matcher: "modal",
  build: title => buildModal(title, "modal", {
    label: "name",
    style: "short",
    customId: "name",
  }, {
    label: "age",
    style: "short",
    customId: "age",
  }),
  run: (ctx) => {
    return ctx.reply(`Your name is ${ctx.values.get("name")} and you are ${ctx.values.get("age")} old !`);
  },
});

// usage
ctx.showModal(modal.build("funny"));

// register
client.loadComponents([modal]);

Event

// declaration
import { createEvent } from "arcscord";

export const messageEvent = createEvent({
  event: "messageCreate", // Djs event
  name: "messageCreate", // OPTIONAL name for logs and debug if you want custom name
  run: (ctx, msg) => {
    ctx.client.logger.info(`message send by ${msg.author.username}!`);
    return ctx.ok(true);
  },
});

// register
client.loadEvents([messageEvent]);

Task

// declaration
import { createTask } from "arcscord";

export const cronTask = createTask({
  interval: "*/10 * * * *", // allowed : duration in ms, cron string or array of cron string
  name: "cron",
  run: (ctx) => {
    console.log(`Running cron task, next run ${ctx.nextRun.toISOString()}`);
    return ctx.ok(true);
  },
});

// register
client.loadTasks([cronTask]);

Localization

full guide soon

import { createCommand } from "arcscord";

export const i18nCommand = createCommand({
  build: {
    slash: {
      name: "i18n",
      nameLocalizations: t => t("test:i18n.command.name"),
      description: "default description",
      descriptionLocalizations: t => t("test:i18n.command.description"),
    },
  },
  run: (ctx) => {
    return ctx.reply(ctx.t("test:i18n.command.run"), {
      ephemeral: true,
    });
  },
});

Go up

0.3.0-beta-7

4 months ago

0.3.0-beta-8

4 months ago

0.3.0-beta-5

4 months ago

0.3.0-beta-6

4 months ago

0.3.0-beta-4

4 months ago

0.3.0-beta-3

4 months ago

0.2.0-beta-1

7 months ago

0.2.0-beta-5

7 months ago

0.2.0-beta-4

7 months ago

0.2.0-beta-3

7 months ago

0.2.0-beta-2

7 months ago

0.2.0

7 months ago

0.1.17

8 months ago

0.1.18

8 months ago

0.1.16

10 months ago

0.1.10

11 months ago

0.1.11

11 months ago

0.1.12

11 months ago

0.1.13

11 months ago

0.1.14

11 months ago

0.1.15

11 months ago

0.1.0

11 months ago

0.1.2

11 months ago

0.1.1

11 months ago

0.1.8

11 months ago

0.1.7

11 months ago

0.1.9

11 months ago

0.1.4

11 months ago

0.1.3

11 months ago

0.1.6

11 months ago

0.1.5

11 months ago

0.3.1-beta

3 years ago

0.3.0-beta

4 years ago

0.2.0-beta

4 years ago

0.1.0-beta

4 years ago

1.0.0

4 years ago