Skip to content

Instantly share code, notes, and snippets.

@BenSegal855
Created December 5, 2022 00:32
Show Gist options
  • Select an option

  • Save BenSegal855/5d01722ae37bbac6430e0d420081ac6a to your computer and use it in GitHub Desktop.

Select an option

Save BenSegal855/5d01722ae37bbac6430e0d420081ac6a to your computer and use it in GitHub Desktop.
Sapphire subcommand test commands
import { ApplyOptions } from '@sapphire/decorators';
import type { ChatInputCommand } from '@sapphire/framework';
import { Subcommand } from '@sapphire/plugin-subcommands';
import type { Message } from 'discord.js';
@ApplyOptions<Subcommand.Options>({
description: 'A subcommand with both message and interaction handlers.',
subcommands: [
{
type: 'method',
name: 's',
messageRun: 'mr',
chatInputRun: 'cr'
}
]
})
export class UserCommand extends Subcommand {
registerApplicationCommands(registry: ChatInputCommand.Registry) {
registry.registerChatInputCommand(builder =>
builder
.setName(this.name)
.setDescription('foo')
.addSubcommand(command => command.setName('s').setDescription('bar'))
);
}
public async mr(message: Message) {
return message.channel.send(`MessageCommands: ${this.supportsMessageCommands()
}\nChatInputCommands: ${this.supportsChatInputCommands()}`);
}
public async cr(interaction: Subcommand.ChatInputInteraction) {
return interaction.reply(`MessageCommands: ${this.supportsMessageCommands()
}\nChatInputCommands: ${this.supportsChatInputCommands()}`);
}
}
import { ApplyOptions } from '@sapphire/decorators';
import type { ChatInputCommand } from '@sapphire/framework';
import { Subcommand } from '@sapphire/plugin-subcommands';
@ApplyOptions<Subcommand.Options>({
description: 'A subcommand with an interaction handler.',
subcommands: [
{
type: 'method',
name: 's',
chatInputRun: 'cr',
}
]
})
export class UserCommand extends Subcommand {
registerApplicationCommands(registry: ChatInputCommand.Registry) {
registry.registerChatInputCommand(builder =>
builder
.setName(this.name)
.setDescription('foo')
.addSubcommand(command => command.setName('s').setDescription('bar'))
);
}
public async cr(interaction: Subcommand.ChatInputInteraction) {
return interaction.reply(`MessageCommands: ${this.supportsMessageCommands()
}\nChatInputCommands: ${this.supportsChatInputCommands()}`);
}
}
import { ApplyOptions } from '@sapphire/decorators';
import { Subcommand } from '@sapphire/plugin-subcommands';
import type { Message } from 'discord.js';
@ApplyOptions<Subcommand.Options>({
description: 'A subcommand with a message handler.',
subcommands: [
{
type: 'method',
name: 's',
messageRun: 'help'
}
]
})
export class UserCommand extends Subcommand {
public async help(message: Message) {
return message.channel.send(`MessageCommands: ${this.supportsMessageCommands()
}\nChatInputCommands: ${this.supportsChatInputCommands()}`);
}
}
import { ApplyOptions } from '@sapphire/decorators';
import type { ChatInputCommand } from '@sapphire/framework';
import { Subcommand } from '@sapphire/plugin-subcommands';
import type { Message } from 'discord.js';
@ApplyOptions<Subcommand.Options>({
description: 'A subcommand with groups and message and interaction handlers.',
subcommands: [
{
type: 'group',
name: 'g',
entries: [
{ name: 'c', messageRun: 'mrc', chatInputRun: 'crc' }
]
},
{
type: 'method',
name: 's',
messageRun: 'mrs',
chatInputRun: 'crs'
}
]
})
export class UserCommand extends Subcommand {
registerApplicationCommands(registry: ChatInputCommand.Registry) {
registry.registerChatInputCommand(builder =>
builder
.setName(this.name)
.setDescription('foo')
.addSubcommand(command => command.setName('s').setDescription('bar'))
.addSubcommandGroup(group =>
group
.setName('g')
.setDescription('baz')
.addSubcommand(command => command.setName('c').setDescription('baf'))
)
);
}
public async mrs(message: Message) {
return message.channel.send(`Source: 'mrs'\nMessageCommands: ${this.supportsMessageCommands()
}\nChatInputCommands: ${this.supportsChatInputCommands()}`);
}
public async crs(interaction: Subcommand.ChatInputInteraction) {
return interaction.reply(`Source: 'crs\n'MessageCommands: ${this.supportsMessageCommands()
}\nChatInputCommands: ${this.supportsChatInputCommands()}`);
}
public async mrc(message: Message) {
return message.channel.send(`Source: 'mrc'\nMessageCommands: ${this.supportsMessageCommands()
}\nChatInputCommands: ${this.supportsChatInputCommands()}`);
}
public async crc(interaction: Subcommand.ChatInputInteraction) {
return interaction.reply(`Source: 'crc'\nMessageCommands: ${this.supportsMessageCommands()
}\nChatInputCommands: ${this.supportsChatInputCommands()}`);
}
}
import { ApplyOptions } from '@sapphire/decorators';
import type { ChatInputCommand } from '@sapphire/framework';
import { Subcommand } from '@sapphire/plugin-subcommands';
@ApplyOptions<Subcommand.Options>({
description: 'A subcommand with groups and interaction handlers.',
subcommands: [
{
type: 'group',
name: 'g',
entries: [
{ name: 'c', chatInputRun: 'crc' }
]
},
{
type: 'method',
name: 's',
chatInputRun: 'crs'
}
]
})
export class UserCommand extends Subcommand {
registerApplicationCommands(registry: ChatInputCommand.Registry) {
registry.registerChatInputCommand(builder =>
builder
.setName(this.name)
.setDescription('foo')
.addSubcommand(command => command.setName('s').setDescription('bar'))
.addSubcommandGroup(group =>
group
.setName('g')
.setDescription('baz')
.addSubcommand(command => command.setName('c').setDescription('baf'))
)
);
}
public async crs(interaction: Subcommand.ChatInputInteraction) {
return interaction.reply(`Source: 'crs'MessageCommands: ${this.supportsMessageCommands()
}\nChatInputCommands: ${this.supportsChatInputCommands()}`);
}
public async crc(interaction: Subcommand.ChatInputInteraction) {
return interaction.reply(`Source: 'crc'MessageCommands: ${this.supportsMessageCommands()
}\nChatInputCommands: ${this.supportsChatInputCommands()}`);
}
}
import { ApplyOptions } from '@sapphire/decorators';
import { Subcommand } from '@sapphire/plugin-subcommands';
import type { Message } from 'discord.js';
@ApplyOptions<Subcommand.Options>({
description: 'A subcommand with command groups and message handlers.',
subcommands: [
{
type: 'group',
name: 'g',
entries: [
{ name: 'c', messageRun: 'mrc' }
]
},
{
type: 'method',
name: 's',
messageRun: 'mrs'
}
]
})
export class UserCommand extends Subcommand {
public async mrs(message: Message) {
return message.channel.send(`Source: 'mrs'\nMessageCommands: ${this.supportsMessageCommands()
}\nChatInputCommands: ${this.supportsChatInputCommands()}`);
}
public async mrc(message: Message) {
return message.channel.send(`Source: 'mrc'\nMessageCommands: ${this.supportsMessageCommands()
}\nChatInputCommands: ${this.supportsChatInputCommands()}`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment