From d3e0955ddca23bd320a7fd4afc1e1b313dc0db04 Mon Sep 17 00:00:00 2001 From: evanwashere Date: Tue, 5 Jul 2022 12:16:52 -0400 Subject: [PATCH] more examples --- .../commands/context_menu/avatar.js | 21 ++++++++ .../discord-interactions/commands/hello.js | 2 +- .../discord-interactions/commands/modal.ts | 51 +++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 examples/discord-interactions/commands/context_menu/avatar.js create mode 100644 examples/discord-interactions/commands/modal.ts diff --git a/examples/discord-interactions/commands/context_menu/avatar.js b/examples/discord-interactions/commands/context_menu/avatar.js new file mode 100644 index 0000000000..fee1ccc689 --- /dev/null +++ b/examples/discord-interactions/commands/context_menu/avatar.js @@ -0,0 +1,21 @@ +import { SlashCommand, ApplicationCommandType } from 'slash-create'; + +export default class AvatarCommand extends SlashCommand { + constructor(creator) { + super(creator, { + // You must specify a type for context menu commands, but defaults + // to `CHAT_INPUT`, or regular slash commands. + type: ApplicationCommandType.USER, + name: 'Get Avatar URL', + }); + + this.filePath = __filename; + } + + async run(ctx) { + // The target user can be accessed from here + // You can also use `ctx.targetMember` for member properties + const target = ctx.targetUser; + return `${target.username}'s Avatar: ${target.avatarURL}`; + } +} \ No newline at end of file diff --git a/examples/discord-interactions/commands/hello.js b/examples/discord-interactions/commands/hello.js index df94931ff5..b72051724e 100644 --- a/examples/discord-interactions/commands/hello.js +++ b/examples/discord-interactions/commands/hello.js @@ -1,4 +1,4 @@ -const { SlashCommand, CommandOptionType } = require('slash-create'); +import { SlashCommand, CommandOptionType } from 'slash-create'; export default class HelloCommand extends SlashCommand { constructor(creator) { diff --git a/examples/discord-interactions/commands/modal.ts b/examples/discord-interactions/commands/modal.ts new file mode 100644 index 0000000000..ed4026ee09 --- /dev/null +++ b/examples/discord-interactions/commands/modal.ts @@ -0,0 +1,51 @@ +import { SlashCommand, ComponentType, TextInputStyle } from 'slash-create'; + +export default class ModalCommand extends SlashCommand { + constructor(creator) { + super(creator, { + name: 'modal', + description: 'Send a cool modal.' + }); + + this.filePath = __filename; + } + + async run(ctx) { + // You can send a modal this way + // Keep in mind providing a callback is optional, but no callback requires the custom_id to be defined. + ctx.sendModal( + { + title: 'Example Modal', + components: [ + { + type: ComponentType.ACTION_ROW, + components: [ + { + type: ComponentType.TEXT_INPUT, + label: 'Text Input', + style: TextInputStyle.SHORT, + custom_id: 'text_input', + placeholder: 'Type something...' + } + ] + }, + { + type: ComponentType.ACTION_ROW, + components: [ + { + type: ComponentType.TEXT_INPUT, + label: 'Long Text Input', + style: TextInputStyle.PARAGRAPH, + custom_id: 'long_text_input', + placeholder: 'Type something...' + } + ] + } + ] + }, + (mctx) => { + mctx.send(`Your input: ${mctx.values.text_input}\nYour long input: ${mctx.values.long_text_input}`); + } + ); + } +} \ No newline at end of file