1.1.2-e • Published 2 years ago

interaction-response v1.1.2-e

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

Discord Interactions handler.

Callbacks:

https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-interaction-callback-type
nametypedescriptionexample
callback.reply4Immediately respond to an interaction.await interaction.callback.reply(event, {ephemeral: false}, { @content: '' } );
callback.defer5Show thinking state, create followup after.await interaction.callback.defer(event, {ephemeral: false});
callback.component_defer6Deferred message for components.await interaction.callback.component_defer(event, {ephemeral: false});
callback.component_update7Components message update.await interaction.callback.component_update(event, {ephemeral: false}, { @content: '' } );
callback.autocomplete_reply8Show autocomplete results
callback.modal_reply9Reply to command with modal popupawait interaction.callback.modal_reply(event, { @content: '' } );
callback.get_original@Get original interaction.await interaction.callback.get_original(event);
callback.edit_original@Edit original interaction.await interaction.callback.edit_original(event, { content: , } );
callback.delete_original@Delete original interaction.await interaction.callback.delete_original(event);

FollowUps:

https://discord.com/developers/docs/interactions/receiving-and-responding#followup-messages
namedescriptionexample
followup.createCreate a followup message for an Interaction.await interaction.followup.create(event, {ephemeral: false}, { @content: '' } );
followup.editEdits a followup message for an Interaction.await interaction.followup.edit(event, {id: @message.id}, { @content: '' } );
followup.getReturns a followup message for an Interaction.await interaction.followup.get(event, {id: @message.id} );
followup.delDeletes a followup message for an Interaction.await interaction.followup.del(event, {id: @message.id} );

Code Examples:

const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const interaction = require('interaction-response');

module.exports = async (event) => {
  await interaction.callback.defer(event, {ephemeral: false});

  const stuff = thing todo here;

  if (stuff) {
    try {
      await interaction.followup.create(event, {ephemeral: false}, {
          content: stuff,
      });
    } catch (e) {
      console.log(e);
    }
  }
};
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const interaction = require('interaction-response');

module.exports = async (event) => {
  await interaction.callback.modal_reply(event, {
    custom_id: `suggestion`,
    title: `Suggestion Box`,
    components: [{
      type: 1,
      components: [{
        type: 4,
        custom_id: "suggestion",
        label: "Suggestion:",
        style: 2,
        min_length: 1,
        max_length: 300,
        placeholder: "I love Ghastli!",
        required: true
      }]
    }]
  });
};
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const interaction = require('interaction-response');

module.exports = async (event) => {
  await interaction.callback.reply(event, {ephemeral: true}, {
      content: '',
      embeds: [
        {
          type: `rich`,
          title: `title`,
          description: `description.`,
          color: 0x082020,
          thumbnail: {
            url: `https://`,
            height: 0,
            width: 0,
          },
          author: {
            name: `author`,
          },
          footer: {
            text: `footer text goes here, you can make it substantial.`,
            icon_url: `https://`,
          },
        },
      ],
      components: [
        {
          type: 1,
          components: [
            {
              style: 2,
              label: `label`,
              custom_id: `id`,
              disabled: false,
              type: 2,
            },
            {
              style: 2,
              label: `label`,
              custom_id: `id`,
              disabled: false,
              type: 2,
            },
            {
              style: 2,
              label: `label`,
              custom_id: `id`,
              disabled: false,
              type: 2,
            },
          ],
        },
      ],
    }
  );
};
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const interaction = require('interaction-response');

module.exports = async (event) => {
  await interaction.callback.component_defer(event, {ephemeral: true});

  if (!event.member.roles.includes(roleid)) {
    await interaction.followup.edit(event, {id: @message.id}, {
      content: ``,
      embeds: [
        {
          type: 'rich',
          title: `Error!`,
          description: `🔔 This is not one of your roles.`,
          color: 0x082020,
        },
      ],
      components: ,
    });
  };

Created in: Created in Autocode. (https://Autocode.com) Autocode.

1.1.2-d

2 years ago

1.1.2-c

2 years ago

1.1.2-e

2 years ago

1.1.2-b

2 years ago

1.1.2-a

2 years ago

1.1.2

2 years ago

1.1.1-a

2 years ago

1.1.0-f

2 years ago

1.1.0-e

2 years ago

1.1.0-d

2 years ago

1.1.0

2 years ago

1.0.2-a

2 years ago

1.0.1-a

2 years ago

1.0.0-a

2 years ago

1.0.0

2 years ago