axislib
v1.1.0
Published
A lib Discord mais fácil e poderosa — por Axis
Maintainers
Readme
AxisLib v1.1.0
A lib Discord mais fácil, tipada e poderosa — feita por Axis.
Instalação
npm install axislibNovidades na v1.1.0
- Evento de menção (
mentionReply) — resposta automática e 100% personalizável quando alguém menciona o bot - Código dividido em módulos —
client/,structures/,managers/,utils/,types/ - Totalmente tipado — todos os builders, options e contextos têm tipos explícitos
- Todos os Components V2 —
container,text,section,thumbnail,separator,gallery,file,row Buttoncomo alias dev2Buttonpara uso clássicoRow<T>genérico — funciona com qualquer componente
Uso básico
import { Client, v2, v2Button, MessageFlags } from "axislib";
const client = new Client({
token: "SEU_TOKEN",
prefix: "!",
owners: ["SEU_ID"],
// Resposta quando alguém menciona o bot — ative e customize como quiser
mentionReply: {
run: async ({ message, client }) => {
await message.reply({
flags: MessageFlags.IsComponentsV2,
components: [
v2.container([
v2.text(`## Oi! Me use com \`/help\`.`),
v2.row(v2Button.primary("help", "Ver comandos")),
], { color: 0x5865F2 }),
],
});
},
},
});
client.slash({
name: "ping",
description: "Pong!",
run: async (client, interaction) => {
await interaction.reply({ content: `Pong! ${client.ws.ping}ms` });
},
});
await client.start();Estrutura do projeto
src/
├── client/
│ └── Client.ts — Classe principal do bot
├── structures/
│ ├── SlashCommand.ts — Estrutura de slash command
│ ├── PrefixCommand.ts — Estrutura de prefix command
│ ├── Event.ts — Estrutura de evento
│ └── Interaction.ts — Estrutura de interaction handler
├── managers/
│ ├── Loader.ts — Carrega arquivos de commands/eventos
│ └── Registry.ts — Registra slash commands na API
├── utils/
│ ├── builders.ts — Todos os builders (v2, v2Button, Embed, Modal...)
│ ├── time.ts — Utilitários de data/hora
│ └── json.ts — JsonDB simples
└── types/
└── index.ts — Todos os tipos e interfacesComponents V2
v2.container(components, options?)
O "card" principal. Aceita todos os outros components v2.
v2.container([...], { color: 0x5865F2, spoiler: false })v2.text(content)
Texto com suporte a Markdown do Discord.
v2.text("## Título\nConteúdo aqui")v2.section(components, accessory?)
Texto à esquerda + thumbnail ou botão à direita.
v2.section([v2.text("Olá!")], v2.thumbnail("https://..."))v2.thumbnail(url, description?)
Imagem pequena para usar como acessório de seção.
v2.thumbnail(member.displayAvatarURL(), "Avatar")v2.separator(size?, divider?)
Linha separadora horizontal.
v2.separator("large")
v2.separator("small", false) // sem linha visívelv2.gallery(images)
Galeria de até 10 imagens.
v2.gallery(["https://img1.png", "https://img2.png"])
v2.gallery([{ url: "https://...", description: "Alt", spoiler: false }])v2.file(url, spoiler?)
Arquivo anexo dentro do container.
v2.file("attachment://banner.png")v2.row(...buttons)
ActionRow de botões dentro de um container v2.
v2.row(v2Button.primary("ok", "OK"), v2Button.danger("no", "Cancelar"))Botões
import { v2Button } from "axislib";
v2Button.primary("id", "Label")
v2Button.secondary("id", "Label")
v2Button.success("id", "Label")
v2Button.danger("id", "Label")
v2Button.link("https://...", "Label")
v2Button.premium("sku-id")
// Com emoji e disabled:
v2Button.primary("id", "Label", { emoji: "✅", disabled: false })Select Menus
import { StringSelect, UserSelect, RoleSelect, ChannelSelect, MentionableSelect, Row } from "axislib";
Row(StringSelect({
customId: "sel",
placeholder: "Escolha",
options: [
{ label: "A", value: "a", emoji: "🅰️" },
{ label: "B", value: "b" },
],
}))
Row(UserSelect({ customId: "user-sel", placeholder: "Usuário" }))
Row(RoleSelect({ customId: "role-sel" }))
Row(ChannelSelect({ customId: "ch-sel", channelTypes: [ChannelType.GuildText] }))
Row(MentionableSelect({ customId: "mention-sel" }))Modal
import { Modal } from "axislib";
await interaction.showModal(Modal({
customId: "form",
title: "Formulário",
inputs: [
{ customId: "nome", label: "Nome", style: "Short", required: true },
{ customId: "bio", label: "Bio", style: "Paragraph", maxLength: 300 },
],
}));Embed (clássico)
import { Embed } from "axislib";
Embed({
title: "Título",
description: "Texto",
color: "#5865F2",
fields: [{ name: "Campo", value: "Valor", inline: true }],
footer: "Rodapé",
thumbnail: "https://...",
timestamp: true,
})Evento de menção
const client = new Client({
token: "...",
mentionReply: {
run: async ({ message, member, channel, client }) => {
// Faça o que quiser aqui!
await message.reply("Oi! 👋");
},
},
});Se
mentionReplynão estiver definido no config, o evento é simplesmente ignorado — sem efeitos colaterais.
Carregamento por arquivo
// Slash command
export default new SlashCommand({
name: "ping",
description: "Pong!",
run: async (client, interaction) => { ... },
});
// Prefix command
export default new PrefixCommand({
name: "ping",
aliases: ["p"],
description: "Pong!",
run: async ({ message }) => { ... },
});
// Evento
export default new EventHandler({
event: "guildMemberAdd",
run: async (client, member) => { ... },
});
// Interaction handler
export default new InteractionHandler({
customId: "meu-botao", // ou "prefixo:*" para wildcard
run: async (client, interaction) => { ... },
});Carregue os diretórios no seu index.ts:
await client
.loadCommands("./dist/commands")
.then(c => c.loadPrefixCommands("./dist/prefix"))
.then(c => c.loadEvents("./dist/events"))
.then(c => c.start());Publicar atualização no npm — passo a passo
1. Fazer o build
npm run buildIsso compila src/ para dist/ (JS + tipos .d.ts).
2. Atualizar a versão no package.json
Edite o campo "version" manualmente, ou use:
npm version patch # 1.1.0 → 1.1.1 (correção de bug)
npm version minor # 1.1.0 → 1.2.0 (novidade sem quebrar)
npm version major # 1.1.0 → 2.0.0 (quebra compatibilidade)3. Login no npm (só na primeira vez)
npm login4. Publicar
npm publishSe o pacote for com escopo (ex: @axis/axislib), adicione --access public:
npm publish --access public5. Verificar
npm view axislib versionDica: inclua sempre o
dist/no.npmignoreao contrário — ou seja, não ignore odist/, mas ignoresrc/,EXAMPLE.ts, etc. Crie um.npmignore:src/ EXAMPLE.ts tsconfig.json
Licença
MIT
