2024-12-18 13:32:15 -06:00
2024-12-18 13:32:15 -06:00
2024-12-16 12:48:18 -06:00
2024-11-10 01:55:07 -06:00
2024-12-16 12:48:18 -06:00
2024-12-18 13:32:15 -06:00
2022-09-18 01:25:31 -05:00
2024-12-16 12:48:18 -06:00

discord.ts

Build good bots fast

This package is in an early Alpha stage and not yet ready for consumption

A solid and simple Discord API wrapper.

Installation

yarn add @jaronp/discord.ts

Quick Start

A small example implementation.

import { Client } from '@jaronp/discord.ts';

// Initialize and configure
const bot = new Client({
    token: '<token>',
    application_id: '<application_id>',
    intents: [
        Intent.GUILDS,
        Intent.GUILD_MESSAGES,
        Intent.GUILD_MESSAGE_REACTIONS,
        Intent.MESSAGE_CONTENT
    ]
});

// Register a listener
bot.handlers.register('READY', (client, context, data) => {
    console.log(`Logged in as ${client.user.tag}`);
});

// Register a command
bot.commands.register('ping', (client, context, args) => {
    context.reply('Pong!', true);
});

// Connect
bot.connect();

Interactions

First create the interactions.

bot.commands.register('test', (_client, context, _args) => {
    // Add components to use interactions
    const msg = new Message().setContent('Test interaction!').addComponent(
        // This generations an action row which can optionaly contain content
        'This is an action row',
        // Create components with helper functions
        Message.button({
            label: 'Click me!',
            style: ComponentStyle.Primary,
            // Assign id's to reference them later
            custom_id: 'click_me',
            emoji: {
                name: '🔥',
                id: null,
                animated: false
            }
        })
    );
    context.reply(msg);
});

Then provide a handler for them.

bot.interactions.register('click_me', async (client, context, interaction) => {
    const response = context.reply(
        `You clicked me! Thank you ${interaction.member.user.username} <3`
    );
});
Languages
TypeScript 93.4%
CSS 6.6%