Setting a command as guild-only

Sometimes, you may need to require a command to only be usable in servers. Maybe it displays server information or gets a server emoji. No matter what it does, setting it as guild-only is straightforward!

First, get the command you want to make guild-only.

const { Command } = require('discord.js-commando');

module.exports = class MeowCommand extends Command {
	constructor(client) {
		super(client, {
			name: 'meow',
			group: 'first',
			memberName: 'meow',
			description: 'Replies with a meow, kitty cat.',
		});
	}

	run(message) {
		return message.say('Meow!');
	}
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

After description, add a guildOnly setting and set it to true.

module.exports = class MeowCommand extends Command {
	constructor(client) {
		super(client, {
			// ...
			guildOnly: true,
		});
	}
};




 



1
2
3
4
5
6
7
8

And that's all there is to it! When used in a DM, the bot will not permit the command's use, and you will no longer receive errors!