C
C#2y 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
KuinoxOP2y ago
The validation error doesn't have any message.
Kuinox
KuinoxOP2y ago
By using the debugger, it looks like it doesn't like that the option name is "":
Kuinox
KuinoxOP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Kuinox
KuinoxOP2y ago
yeah i keep digging it, it looks like it's not the issue but a validation of the lib
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Kuinox
KuinoxOP2y ago
i'm trying to stepping in the validation error
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Kuinox
KuinoxOP2y ago
the stacktrace is throwed below the validation
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Kuinox
KuinoxOP2y ago
ok, i'll run the thing by hand to see if it's that
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Kuinox
KuinoxOP2y ago
WAIT WHAT
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Kuinox
KuinoxOP2y ago
AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH IM A MORON
Kuinox
KuinoxOP2y ago
AHHHHHHHHHHHHHHHHHHHHHHHHHH
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Kuinox
KuinoxOP2y ago
yeah
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Kuinox
KuinoxOP2y ago
I'll agree with that :D i'll put the thing as resolved then
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Kuinox
KuinoxOP2y ago
i'll close the post :D
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server