C
C#17mo ago
Kuinox

✅ Validation Error with Discord.Addons.Hosting

I'm trying to use Discord.Addons.Hosting, but it throws an OptionsValidationException . My main looks like this:
var host = new HostBuilder()
.ConfigureAppConfiguration( ( hostingContext, config ) =>
{
config.AddJsonFile( "appsettings.json", optional: false );
} )
.ConfigureLogging( x =>
{
x.AddConsole();
} )
.ConfigureDiscordHost( ( context, config ) =>
{
config.SocketConfig = new DiscordSocketConfig
{
LogLevel = LogSeverity.Debug,
AlwaysDownloadUsers = true,
GatewayIntents = GatewayIntents.All,
MessageCacheSize = 200
};
var openAIConfig = context.Configuration.GetSection( "OpenAPIConfig" ).Get<OpenAIAPIConfig>();
config.Token = openAIConfig.ApiKey;
} )
.UseInteractionService( (context, config) =>
{
config.UseCompiledLambda = true;
} )
.UseCommandService((context, config) =>
{
} )
.ConfigureServices( ( hostContext, services ) =>
{

services
.Configure<DiscordSocketConfig>( hostContext.Configuration.GetSection( "DiscordConfig" ) )
.Configure<KuinoxSemiAGI.DiscordConfig>( hostContext.Configuration.GetSection( "DiscordConfig" ) )
.AddSingleton<OpenAIAPI>()
.AddSingleton<DiscordAskChatGPT>()
;
} )
.Build();

await host.RunAsync();
var host = new HostBuilder()
.ConfigureAppConfiguration( ( hostingContext, config ) =>
{
config.AddJsonFile( "appsettings.json", optional: false );
} )
.ConfigureLogging( x =>
{
x.AddConsole();
} )
.ConfigureDiscordHost( ( context, config ) =>
{
config.SocketConfig = new DiscordSocketConfig
{
LogLevel = LogSeverity.Debug,
AlwaysDownloadUsers = true,
GatewayIntents = GatewayIntents.All,
MessageCacheSize = 200
};
var openAIConfig = context.Configuration.GetSection( "OpenAPIConfig" ).Get<OpenAIAPIConfig>();
config.Token = openAIConfig.ApiKey;
} )
.UseInteractionService( (context, config) =>
{
config.UseCompiledLambda = true;
} )
.UseCommandService((context, config) =>
{
} )
.ConfigureServices( ( hostContext, services ) =>
{

services
.Configure<DiscordSocketConfig>( hostContext.Configuration.GetSection( "DiscordConfig" ) )
.Configure<KuinoxSemiAGI.DiscordConfig>( hostContext.Configuration.GetSection( "DiscordConfig" ) )
.AddSingleton<OpenAIAPI>()
.AddSingleton<DiscordAskChatGPT>()
;
} )
.Build();

await host.RunAsync();
23 Replies
Kuinox
Kuinox17mo ago
The validation error doesn't have any message.
Kuinox
Kuinox17mo ago
By using the debugger, it looks like it doesn't like that the option name is "":
Kuinox
Kuinox17mo ago
what I don't understand is that, even if I set the config section set, it still have an empty name: .Configure<DiscordHostConfiguration>( hostContext.Configuration.GetSection( "DiscordHostConfiguration" ) )
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Kuinox
Kuinox17mo ago
yeah i keep digging it, it looks like it's not the issue but a validation of the lib
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Kuinox
Kuinox17mo ago
i'm trying to stepping in the validation error
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Kuinox
Kuinox17mo ago
the stacktrace is throwed below the validation
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Kuinox
Kuinox17mo ago
ok, i'll run the thing by hand to see if it's that
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Kuinox
Kuinox17mo ago
WAIT WHAT
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Kuinox
Kuinox17mo ago
AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH IM A MORON
Kuinox
Kuinox17mo ago
AHHHHHHHHHHHHHHHHHHHHHHHHHH
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Kuinox
Kuinox17mo ago
yeah
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Kuinox
Kuinox17mo ago
I'll agree with that :D i'll put the thing as resolved then
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Kuinox
Kuinox17mo ago
i'll close the post :D
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View