Prefix Commands
Setting up prefixes
Not only does seyfert handle application commands but also prefix commands
. They are not enabled by default but you can enable them by setting up an option inside the ClientOptions
. We have to access to the command
option where we can specify a suboption called prefix
. This option expects a callback returning an array of possible prefixes for that command. As the callback returns a Message
is pretty simple to handle diffrent prefixes per guild.
Here is an example in which we are going to set multiple prefixes for all the commands.
Handling prefix commands
Having set up our prefixes for the commands it’s about time we want to make them run.
And for your luck, the handling works as application commands. The only difference is that we receive an optional Message
property inside CommandContext
.
To make this property appear in our CommandContext the only thing we shall do is declaring seyfert module and set the withPrefix
property inside InternalOptions
into true. You can see this detailed example.
In this example we are going to create a command which cross post
the message that was sent in an announcement channel.
Ignoring
You can decide whether a command will ignore being a slash command or a prefix command.
Replying to prefix commands
By default when you use write
or editOrReply
function it will only send a message to the channel where the command was fired. To make the command being replied you have to set reply
suboption inside command
option in the client options. This option is a callback which first parameter is the CommandContext
and expects a boolean to be returned, if is true
it will reply to the command, if not it will just send a message.
Here is a detailed example about how it will looks your client with all the modifications mentioned in this guide:
Prefix commands options
Like application commands
you can set options for prefix commands
. The only think you will have to do it’s to declare them as you do in application commands
. They are parsed with a regex that indicates options will be splited when they are followed by -
. You can replace the parser with your own parser in the argsParser
suboption inside commands
options in client options. This is a callback whose params are content
, the content of the message, and command
, the command which was run and expects an object whose keys are the options and values the values of the options.
Here is a brief template which shows how options work in prefix commands.
Here you can see how we make the previous command but instead of cross posting the current command cross posing another message, fetching it by its id that will be given to us in the options.
Defering the reply with prefix commands
As in application commands
you can defer reply the response of the command. By default if you use CommandContext.deferReply()
function it will make the response to be deferred showing a Loading ...
message. If we want it to be custom we will have to take another look into commands
option in client options as we have to create a callback for deferReplyResponse
which expects the content you will send in the defer to be returned.
Here is an example of how we modify the client options and how we make the response of the command to be deferred using the previous example.