Skip to main content

Setting the types of channel a command can run in

The runIn command option can be used to specify the types of channels a command can run in. This can be useful if you're developing a command that, for example, displays the roles of a user. In that scenario, you'll want to make sure that the command can only be run in guild channels.


You can view the valid runIn values here.

import { Command, CommandOptionsRunTypeEnum } from '@sapphire/framework';

export class PingCommand extends Command {
public constructor(context: Command.Context) {
super(context, {
// ...
runIn: CommandOptionsRunTypeEnum.GuildAny // Only run in guild channels

If you try to run a command in direct messages, you'll now find that nothing happens.


To learn how to send a message to the command executor when a precondition fails, see Reporting Precondition Failure.