0.1.1 • Published 2 years ago

@jaronp/discord.ts v0.1.1

Weekly downloads
-
License
Unlicense
Repository
github
Last release
2 years ago

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

Quick Start

A small example implementation.

// 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`
    );
});
0.1.1

2 years ago

0.1.0

2 years ago