0.0.1-dev.1659027321767.52ccab3 • Published 4 years ago

reaccord v0.0.1-dev.1659027321767.52ccab3

Weekly downloads
-
License
-
Repository
-
Last release
4 years ago

A simple, and clean framework to build discord apps declaratively using React + JSX and Discord.js.

Explore the docs...

Let's build a simple counter

View complete typescript example here

imports

import {
    ButtonStyle,
    ChatInputCommand,
    Client,
    GatewayIntentBits,
} from "reaccord"
import { useState } from "react"

Define App behavior, just like in a React app.

export const CounterApp = ({ start = 0 }) => {
    const [count, setCount] = useState(start)
    const increment = () => setCount((count) => count + 1)

    return (
        <>
            <content>Count: {count}</content>
            <action-row>
                <button onClick={increment} style={ButtonStyle.Primary}>
                    +
                </button>
            </action-row>
        </>
    )
}

Create end-user command.

const counterCommand = new ChatInputCommand("counter", "A simple counter")
    .intParam("start", "Number to start counting from")
    .render(CounterApp)

Instantiate the gateway client, and register the command.

const client = new Client({
    token: DISCORD_TOKEN ?? "",
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.GuildMessageReactions,
    ],
    devGuildId: DISCORD_DEV_GUILD_ID,
    clientId: DISCORD_CLIENT_ID,
})

client.registerCommand(counterCommand)

// Connect client to gateway
client.connect(() =>
    console.log(`🚀 Client connected as ${client.user?.username}!`),
)
0.0.0-dev

4 years ago

0.0.1-dev

4 years ago