Creating commands
In this section you will learn how to create simple commands with the Command
abstract class from the Guilded.TS framework.
Creating a command
Lets start by creating a folder named commands
in the root directory, this will be used to store your commands. After you have made a commands
directory, create a file named ping.{js,ts}
inside it, this will be your ping command. Inside the file, add the following:
import { Command } from '@guildedts/framework';
import { Message } from 'guilded.ts';
export default class extends Command {
execute(message: Message) {
message.reply('Pong!');
}
}
const { Command } = require('@guildedts/framework');
module.exports = class extends Command {
execute(message) {
message.reply('Pong!');
}
}
import { Command } from '@guildedts/framework';
export default class extends Command {
execute(message) {
message.reply('Pong!');
}
}
Examples
TIP
By default, the command name is the name of the file without the extension. For example, ping.js
is ping
.
Using args
import { Command, StringArgument } from '@guildedts/framework';
import { Message } from 'guilded.ts';
export default class extends Command {
arguments = [
class extends StringArgument {
name = 'content';
}
]
execute(message: Message, { content }: { content: string }) {
message.reply(content);
}
}
const { Command, StringArgument } = require('@guildedts/framework');
module.exports = class extends Command {
arguments = [
class extends StringArgument {
name = 'content';
}
]
execute(message, { content }) {
message.reply(content);
}
}
import { Command, StringArgument } from '@guildedts/framework';
export default class extends Command {
arguments = [
class extends StringArgument {
name = 'content';
}
]
execute(message, { content }) {
message.reply(content);
}
}
Examples
TIP
There are different types of arguments, see the list below:
Argument
StringArgument
BooleanArgument
NumberArgument
:::