1.0.4 • Published 3 years ago

@gcommands/expressinteraction v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

EXPRESS VERSION OF GCOMMANDS

Installation

Install with npm / yarn / pnpm:

npm install @gcommands/expressinteraction
yarn add @gcommands/expressinteraction
pnpm add @gcommands/expressinteraction

Usage

You go to your bot at https://discord.com/developers and copy the publicKey which you then put into the clientPublicKey parameter. In the Interaction Endpoint Url you put your site url and to that endpoint which you then put in the interactionEnpoint parameter, for example /interactions so in the discord panel you put https://example.com/interactions. You can receive interactions via the GExpressInteraction event

// Without CMD Handler
const { GExpressInteraction } = require("@gcommands/expressinteraction");

let g = new GExpressInteraction({
  interactionEndpoint: "/interactions", // Interactions Endpoint URL 
  clientPublicKey: process.env.publicKey, // Public Key from https://discord.com/developer/applications/:ID/information
  port: 3e3 // express port
})

g.on("GExpressInteraction", (interaction) => {
  if(interaction.isCommand()) {
    interaction.send("po") // https://gcommands.js.org/docs/#/docs/main/main/typedef/GPayloadOptions
  }
})

// With CMD Handler
const { GExpressInteraction } = require("@gcommands/expressinteraction");

let g = new GExpressInteraction({
  cmdDir: "cmds/",
  interactionEndpoint: "/interactions", // Interactions Endpoint URL 
  clientPublicKey: process.env.publicKey, // Public Key from https://discord.com/developer/applications/:ID/information
  port: 3e3 // express port
})

If you want a straight cmd handler, you can create for example test.js in cmds/ and put it there:

const { Command } = require("@gcommands/expressinteraction")

module.exports = class extends Command {
  constructor(...args) {
    super(...args, {
      name: "test"
    })
  }

  run({respond}, arrayArgs, args) {
    respond("hello")
  }
}

To create a slash command, go to panel. GExpressInteraction is used only for the handle.