mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
more examples
This commit is contained in:
committed by
Jarred Sumner
parent
5d4fbf7f02
commit
d3e0955ddc
@@ -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}`;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
const { SlashCommand, CommandOptionType } = require('slash-create');
|
||||
import { SlashCommand, CommandOptionType } from 'slash-create';
|
||||
|
||||
export default class HelloCommand extends SlashCommand {
|
||||
constructor(creator) {
|
||||
|
||||
51
examples/discord-interactions/commands/modal.ts
Normal file
51
examples/discord-interactions/commands/modal.ts
Normal file
@@ -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}`);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user