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.

info

You can view the valid runIn values here.

const { Command, CommandOptionsRunTypeEnum } = require('@sapphire/framework');

class PingCommand extends Command {
constructor(context) {
super(context, {
// ...
runIn: CommandOptionsRunTypeEnum.GuildAny // Only run in guild channels
});
}
}
module.exports = {
PingCommand
};

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

tip

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