Guild-only Commands

Sometimes your command can only be executed in a guild context.

For those cases Discapp alows you to mark commands as guild-only, this means trying to execute this command from the bot private chat, for example, will not work.

In this chapter we will code the MakeChannelCommand that receives the name of the channel as argument and creates it.

Writing the MakeChannelCommand#

path/to/your/app/src/Commands/MakeChannel.ts
import { Command, BaseCommand, Guild, GuildContract, Argument } from "discapp";
@Command({
isGuildOnly: true,
})
export class MakeChannelCommand extends BaseCommand {
@Argument()
public name: string;
@Guild()
public guild: GuildContract;
public execute() {
this.guild.channels.create(this.name);
}
}

Notice that we've added an argument to our @Command() decorator before the class declaration.

Actually this argument can receive lots of data about your command, tha are covered in another chapters.

Also notice the @Guild() decorator that allows us to retrieve the Guild.

Testing the MakeChannelCommand#

You can test the MakeChannelCommand by sending:

!make-channel new-channel

Your bot should create a channel called new-channel.

danger

Make sure yout bot has the permissions for creating a channel.

In the chapter Command Permissions you can learn more about it.