Git Product home page Git Product logo

interactions.js's Introduction

Table of Contents

About

interactions.js is a powerful Node.js module that makes it easy to create and handle Discord interactions. It provides a comprehensive set of features and utilities that help developers to seamlessly integrate interactions into their Discord bots and applications.

Some key features of interactions.js include:

  • Object-oriented: Interactions are represented as classes which makes the API simple and intuitive to use.
  • Performant: Built on top of discord.js and optimized for performance.
  • Inbuilt Cache: Comes with an in-memory cache to store interactions for faster responses.
  • Easy to use: Simple and intuitive API that is easy to integrate into existing bots and applications.
  • Robust: Provides utilities for building complex interactions with features like autocomplete, modal forms etc.
  • Extensible: Easy to extend and customize through plugins and middleware.

Getting Started

Installation

Prerequisites: Node.js 16.9.0 or newer is required.

  • To install interactions.js, run the following command:
npm install interactions.js

//This installs interactions.js and its dependencies using npm.

Example

Here is a basic example of how to get started with interactions.js:

  • Create an Application instance
const { Application } = require("interactions.js");

  const Client = new Application({
    botToken: process.env.TOKEN, // Your Bot Token
    publicKey: process.env.PUBLICKEY, // The Application Public Key
    applicationId: process.env.APPLICATIONID, // The Application ID
  });

This creates the Application instance with the required authentication details and starts the client. It connects to Discord and initializes the interactions.js library.

  • Start the client:
  Client.start().then(() => {
     console.log("Client Started");
    });  

  Client.on("debug", debug => console.log(debug));

This logs any debug information from the client to the console.

  • Create an Interaction Command:
   Client.setAppCommands([{
    name: "ping",
    description: "Pong!",
        },
    ]).catch(console.log);

This creates a ping command and registers it with the client. The .catch() handles any errors from registering the command.

  • Create Handle interaction events:
// Handle interaction events:
Client.on("interactionCreate", async (i) => {
  if (i.commandName === "ping") {
    return i.reply({
      content: "Pong!",
      ephemeral: true,
    });
  }
});
See Full Example Code
    const { Application } = require("interactions.js");

    const Client = new Application({
            botToken: process.env.TOKEN, // Your Bot Token
            publicKey: process.env.PUBLICKEY, // The Application Public Key
            applicationId: process.env.APPLICATIONID, // The Application ID
        });

        /**
         * After calling start(), the api starts on port 8221 in this example and you need to set your application's interaction url to https://your-domain.com/interactions
         * 
         * The /interactions parts is required and you can't change it.
         */

    Client.start().then(() => {
        console.log("Client Started");
        });  

    Client.on("debug", debug => console.log(debug));

    // Create an Interaction Command:
    Client.setAppCommands([{
        name: "ping",
        description: "Pong!",
            },
        ]).catch(console.log);

    // Handle interaction events:
    Client.on("interactionCreate", async (i) => {
    if (i.commandName === "ping") {
        return i.reply({
        content: "Pong!",
        ephemeral: true,
        });
    }
    });

    //Once you have followed these steps, you will be able to start receiving and handling interactions from your Discord bot.

see above code for details on setting up interactions.js client and registering commands

Example way to get the guild count

const { UserManager } = require("interactions.js");
const application = await UserManager.fetchMyApplication();

// Note: This is not the actual guild count, but an approximation
const guildCount = application.approximate_guild_count;

Help

If you have questions, encounter issues, or need guidance, feel free to join our Discord server. We have an active community of developers happy to help!

Example Handler

Check out http-bot-template for an example of how to use interactions.js in a bot project.

Bots Using interactions.js

Some notable bots that use interactions.js include:

interactions.js's People

Contributors

fb-sean avatar mezotv avatar petsamuel avatar dependabot[bot] avatar zaptoinc avatar notjag avatar meister03 avatar devdeem avatar deepsourcebot avatar deepsarda avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.