Configuration
This page will cover the configuration part of the interaction library.
Configuring the library for the Botrino framework
For the library to work with the Botrino framework, you just need to make sure that your bot
module requires botrino.interaction
, and that the interaction
entry is present in your config.json
. The entry has
the following structure:
{
"interaction": {
"application_commands_guild_id": null,
"private_commands_guild_id": null,
"default_ack_mode": "default",
"await_component_timeout_seconds": 600
}
}
Field | Type | Description | Required? |
---|---|---|---|
application_commands_guild_id | long | The ID of the guild in which commands will be deployed. Specifying null or completely omitting the field will deploy them globally. | No, default null |
private_commands_guild_id | long | The ID of the guild in which commands marked with @PrivateCommand will be deployed. Specifying null or completely omitting the field will not deploy them at all. | No, default null |
default_ack_mode | string | How interactions should be acknowledged by default. Possible values (case insensitive):
| No, default default |
await_component_timeout_seconds | integer | The time in seconds after which InteractionContext::awaitComponentInteraction automatically times out. | No, default 600 |
Configuring the library manually
If you don't use the framework, the configuration is done via the InteractionConfig
object, which is used to
construct InteractionService
:
// Use default values
final var config = InteractionConfig.withDefaults();
// Use custom values
final var config = InteractionConfig.builder()
.applicationCommandsGuildId(123456L)
.privateCommandsGuildId(123456L)
.defaultACKMode("default")
.awaitComponentTimeoutSeconds(600)
.build();
// Login to Discord using the token passed as program argument
final var gateway = DiscordClient.create(args[0]).login().block();
// Initialize the interaction service
final var interactionService = InteractionService.create(config, gateway);
The methods available in InteractionConfig::builder
are the same as the ones in the JSON described previously.
Once you have the InteractionService
instance, you can register your commands and subscribe to its run()
method:
// Register your commands
interactionService.registerChatInputCommand(new PingCommand());
// Listen for interaction events until the bot disconnects
interactionService.run().takeUntilOther(gateway.onDisconnect()).block();
None of this is necessary when using the Botrino framework. Creation of InteractionConfig
and InteractionService
,
registration of commands and execution of the run()
method are all done automatically.