npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

discord-bot-framework-ts

v1.0.3

Published

Um framework robusto para criar bots do Discord em TypeScript

Downloads

305

Readme

Discord Bot Framework TypeScript

Um framework robusto e tipado para criar bots do Discord em TypeScript de forma simples e organizada.

Features

  • Totalmente tipado com TypeScript
  • Decorators para comandos
  • Suporte a comandos tradicionais e Slash Commands
  • Sistema de eventos modular
  • Tratamento de erros embutido
  • Estrutura organizada e escalável

Instalação

npm install discord-bot-framework-ts

Uso Básico

Configuração Inicial

// src/index.ts
import { Bot } from 'discord-bot-framework-ts';
import { join } from 'path';
import dotenv from 'dotenv';

dotenv.config();

const bot = new Bot({
    token: process.env.DISCORD_TOKEN!,
    prefix: '!'
});

async function main() {
    await bot.loadCommands(join(__dirname, 'commands'));
    await bot.loadEvents(join(__dirname, 'events'));
    await bot.start();
}

main();

Criando um Comando

// src/commands/PingCommand.ts
import { Message } from 'discord.js';
import { BaseCommand, Command } from 'discord-bot-framework-ts';

@Command({
    name: 'ping',
    description: 'Responde com Pong!'
})
export default class PingCommand extends BaseCommand {
    async execute(message: Message, args: string[]): Promise<void> {
        await message.reply('Pong!');
    }
}

Criando um Slash Command

// src/commands/SlashPingCommand.ts
import { BaseSlashCommand, Command } from 'discord-bot-framework-ts';
import { ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js';

@Command({
    name: 'ping',
    description: 'Mostra a latência do bot'
})
export default class SlashPingCommand extends BaseSlashCommand {
    getData() {
        return new SlashCommandBuilder()
            .setName('ping')
            .setDescription('Mostra a latência do bot');
    }

    async execute(interaction: ChatInputCommandInteraction): Promise<void> {
        await interaction.reply('Pong!');
    }
}

Criando um Evento

// src/events/ReadyEvent.ts
import { BaseEvent } from 'discord-bot-framework-ts';
import { Client } from 'discord.js';

export default class ReadyEvent extends BaseEvent {
    constructor() {
        super('ready', true);
    }

    async execute(client: Client): Promise<void> {
        console.log(`Bot está online como ${client.user?.tag}`);
    }
}

Estrutura de Pastas Recomendada

seu-bot/
├── src/
│   ├── commands/         # Comandos tradicionais e Slash Commands
│   ├── events/          # Eventos do bot
│   └── index.ts         # Arquivo principal
├── .env                 # Variáveis de ambiente
├── package.json
└── tsconfig.json

Configuração Completa

  1. Instale as dependências necessárias:
npm init -y
npm install discord-bot-framework-ts discord.js dotenv
npm install -D typescript @types/node ts-node
  1. Configure o tsconfig.json:
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "rootDir": "./src",
    "outDir": "./dist",
    "strict": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "skipLibCheck": true
  }
}
  1. Configure o .env:
DISCORD_TOKEN=seu_token_aqui
CLIENT_ID=id_do_seu_bot

Contribuindo

Contribuições são sempre bem-vindas. Por favor, siga os passos abaixo:

  1. Faça o fork do projeto
  2. Crie sua feature branch (git checkout -b feature/NovaFuncionalidade)
  3. Commit suas mudanças (git commit -m 'Add: alguma funcionalidade')
  4. Push para a branch (git push origin feature/NovaFuncionalidade)
  5. Abra um Pull Request

Licença

Este projeto está sob a licença MIT. Veja o arquivo LICENSE para mais detalhes.

Suporte

Se você tiver alguma dúvida sobre o framework, sinta-se à vontade para abrir uma issue no GitHub.