Skip to main content

Text Commands

caution

A text command is dependent on the content of the message but unfortunately, Discord plans to remove message content for verified bots and apps, those with 100 or more servers. Hence, You cannot use text commands if your bot cannot access message content.

Read discord message here

Create a simple command handler for messages using @TextCommand.

src/app.service.ts
import { Injectable } from '@nestjs/common';
import { Context, TextCommand, TextCommandContext, Arguments } from '@globalart/nestcord';

@Injectable()
export class AppService {
@TextCommand({
name: 'ping',
description: 'Ping command!',
})
public onPing(@Context() [message]: TextCommandContext) {
return message.reply('pong!');
}
}

If all goes well, you should see something like this:

Text Command

Arguments

You can also use arguments with text commands. Arguments are the words after the command name.

src/app.service.ts
import { Injectable } from '@nestjs/common';
import { Context, TextCommand, TextCommandContext, Arguments } from '@globalart/nestcord';

@Injectable()
export class AppService {
@TextCommand({
name: 'echo',
description: 'Echo command!',
})
public onEcho(@Context() [message]: TextCommandContext, @Arguments() args: string[]) {
return message.reply(args.join(' '));
}
}