@@ -20,8 +20,8 @@ public static class DependencyInjection
20
20
/// <param name="botToken">Token of the bot.</param>
21
21
/// <param name="config">Additional options to configure bot with.</param>
22
22
public static IServiceCollection AddDiscordSocketClient ( this IServiceCollection services ,
23
- string botToken , Action < DiscordSocketConfig > config = null ) =>
24
- services . AddSingleton < DiscordSocketClient , DiscordSocketClientWrapper > ( )
23
+ string botToken , Action < DiscordSocketConfig > ? config = null ) =>
24
+ services . AddSingleton < IDiscordClient , DiscordSocketClientWrapper > ( )
25
25
. Configure < DiscordSocketConfigWrapper > ( localConfig =>
26
26
{
27
27
localConfig . BotToken = botToken ;
@@ -30,7 +30,7 @@ public static IServiceCollection AddDiscordSocketClient(this IServiceCollection
30
30
31
31
private class DiscordSocketConfigWrapper : DiscordSocketConfig
32
32
{
33
- public string BotToken { get ; set ; }
33
+ public string ? BotToken { get ; set ; }
34
34
}
35
35
private class DiscordSocketClientWrapper : DiscordSocketClient
36
36
{
@@ -48,7 +48,7 @@ public DiscordSocketClientWrapper(ILogger<DiscordSocketClient> logger,
48
48
return Task . CompletedTask ;
49
49
} ;
50
50
51
- Run ( config . Value . BotToken ) . ConfigureAwait ( false ) ;
51
+ Run ( config . Value . BotToken ! ) . ConfigureAwait ( false ) ;
52
52
}
53
53
54
54
private async Task Run ( string token )
@@ -64,23 +64,23 @@ private async Task Run(string token)
64
64
/// <param name="services"><see cref="IServiceCollection"/> to add to.</param>
65
65
/// <param name="config">Additional options to configure bot with.</param>
66
66
public static IServiceCollection AddCommandService ( this IServiceCollection services ,
67
- Action < CommandServiceConfig > config = null ) =>
67
+ Action < CommandServiceConfig > ? config = null ) =>
68
68
services . AddSingleton < CommandService , CommandServiceWrapper > ( ) . Configure ( config ) ;
69
69
70
70
private class CommandServiceWrapper : CommandService
71
71
{
72
- public CommandServiceWrapper ( DiscordSocketClient client , ILogger < CommandService > logger ,
72
+ public CommandServiceWrapper ( IDiscordClient client , ILogger < CommandService > logger ,
73
73
IOptions < CommandServiceConfig > cmdServiceConfig , IConfiguration config ) : base ( cmdServiceConfig . Value )
74
74
{
75
75
if ( ulong . TryParse ( config [ "LoggingChannelId" ] , out var loggingChannelId ) )
76
76
{
77
+ var channel = ( IMessageChannel ) client . GetChannelAsync ( loggingChannelId ) . Result ;
77
78
Log += async message =>
78
79
{
79
80
if ( message . Exception is CommandException commandException )
80
81
{
81
- await ( ( IMessageChannel ) client . GetChannel ( loggingChannelId ) )
82
- . SendMessageAsync (
83
- $ "```{ commandException . Message } \n { commandException . InnerException } ```") ;
82
+ await channel . SendMessageAsync (
83
+ $ "```{ commandException . Message } \n { commandException . InnerException } ```") ;
84
84
}
85
85
} ;
86
86
}
0 commit comments