What are inhibitors?

The inhibitor is used to check/execute a function before starting a command. They are terribly useful because at least you don't have to duplicate code in every command.

GCommands already comes with default inhibitors and these are:

  • ChannelOnly
  • ClientPermissions
  • ClientRoles
  • Nsfw
  • Or
  • UserOnly
  • MemberPermissions
  • MemberRoles

Simply import them in the command, and then add them to the inhibitors parameter.

const {
	Command,
	Inhibitor: { ChannelOnly },
} = require('gcommands');

new Command({
	name: 'inhibitor-test',
	inhibitors: [
		new ChannelOnly({
			ids: ['channelId', 'channelId 2'],
			message: 'You can\'t use this command here!',
			ephemeral: true,
		}),
	],
	...other,
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

You may be saying to yourself, what is OrInhibitor for. You can put 2 inhibitors in there, for example UserOnly and ChannelOnly and as long as one of those inhibitors is satisfied, the code will continue.

const {
	Command,
	Inhibitor: { ChannelOnly, UserOnly, Or },
} = require('gcommands');

new Command({
	name: 'inhibitor-test',
	inhibitors: [
		new Or({
			inhibitors: [
				new ChannelOnly({
					ids: ['channelId', 'channelId 2'],
				}),
				new UserOnly({
					ids: ['userId', 'userId 2'],
				}),
			],
			message: 'You can\'t use this command here!',
			ephemeral: true,
		}),
	],
	...other,
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

You put something different in each inhibitor. See documentationopen in new window for more information.