diff --git a/_examples/application_commands/gateway/example.go b/_examples/application_commands/gateway/example.go index 27c04958..7f8b74c9 100644 --- a/_examples/application_commands/gateway/example.go +++ b/_examples/application_commands/gateway/example.go @@ -10,7 +10,6 @@ import ( "github.com/disgoorg/disgo/bot" "github.com/disgoorg/disgo/discord" "github.com/disgoorg/disgo/events" - "github.com/disgoorg/disgo/gateway" "github.com/disgoorg/log" "github.com/disgoorg/snowflake/v2" ) @@ -45,7 +44,7 @@ func main() { log.Info("disgo version: ", disgo.Version) client, err := disgo.New(token, - bot.WithGatewayConfigOpts(gateway.WithIntents(gateway.IntentsNone)), + bot.WithDefaultGateway(), bot.WithEventListenerFunc(commandListener), ) if err != nil { diff --git a/_examples/application_commands/localization/example.go b/_examples/application_commands/localization/example.go index 25faa406..552c5895 100644 --- a/_examples/application_commands/localization/example.go +++ b/_examples/application_commands/localization/example.go @@ -10,7 +10,6 @@ import ( "github.com/disgoorg/disgo/bot" "github.com/disgoorg/disgo/discord" "github.com/disgoorg/disgo/events" - "github.com/disgoorg/disgo/gateway" "github.com/disgoorg/log" "github.com/disgoorg/snowflake/v2" ) @@ -69,7 +68,7 @@ func main() { log.Infof("disgo version: %s", disgo.Version) client, err := disgo.New(token, - bot.WithGatewayConfigOpts(gateway.WithIntents(gateway.IntentsNone)), + bot.WithDefaultGateway(), bot.WithEventListenerFunc(commandListener), ) if err != nil { diff --git a/bot/config.go b/bot/config.go index bebd72d3..2ffbfcc7 100644 --- a/bot/config.go +++ b/bot/config.go @@ -121,6 +121,13 @@ func WithGateway(gateway gateway.Gateway) ConfigOpt { } } +// WithDefaultGateway creates a gateway.Gateway with sensible defaults. +func WithDefaultGateway() ConfigOpt { + return func(config *Config) { + config.GatewayConfigOpts = append(config.GatewayConfigOpts, func(_ *gateway.Config) {}) + } +} + // WithGatewayConfigOpts lets you configure the default gateway.Gateway. func WithGatewayConfigOpts(opts ...gateway.ConfigOpt) ConfigOpt { return func(config *Config) { @@ -135,6 +142,13 @@ func WithShardManager(shardManager sharding.ShardManager) ConfigOpt { } } +// WithDefaultShardManager creates a sharding.ShardManager with sensible defaults. +func WithDefaultShardManager() ConfigOpt { + return func(config *Config) { + config.ShardManagerConfigOpts = append(config.ShardManagerConfigOpts, func(_ *sharding.Config) {}) + } +} + // WithShardManagerConfigOpts lets you configure the default sharding.ShardManager. func WithShardManagerConfigOpts(opts ...sharding.ConfigOpt) ConfigOpt { return func(config *Config) { @@ -224,7 +238,7 @@ func BuildClient(token string, config Config, gatewayEventHandlerFunc func(clien } client.eventManager = config.EventManager - if config.Gateway == nil && config.GatewayConfigOpts != nil { + if config.Gateway == nil && len(config.GatewayConfigOpts) > 0 { var gatewayRs *discord.Gateway gatewayRs, err = client.restServices.GetGateway() if err != nil { @@ -246,7 +260,7 @@ func BuildClient(token string, config Config, gatewayEventHandlerFunc func(clien } client.gateway = config.Gateway - if config.ShardManager == nil && config.ShardManagerConfigOpts != nil { + if config.ShardManager == nil && len(config.ShardManagerConfigOpts) > 0 { var gatewayBotRs *discord.GatewayBot gatewayBotRs, err = client.restServices.GetGatewayBot() if err != nil { @@ -281,7 +295,7 @@ func BuildClient(token string, config Config, gatewayEventHandlerFunc func(clien } client.shardManager = config.ShardManager - if config.HTTPServer == nil && config.PublicKey != "" && config.HTTPServerConfigOpts != nil { + if config.HTTPServer == nil && config.PublicKey != "" { config.HTTPServerConfigOpts = append([]httpserver.ConfigOpt{ httpserver.WithLogger(client.logger), }, config.HTTPServerConfigOpts...)