@@ -50,11 +50,9 @@ public async Task StartAsync()
50
50
//
51
51
// If you do not use Dependency Injection, pass null.
52
52
// See Dependency Injection guide for more information.
53
- using ( var scope = _services . CreateScope ( ) )
54
- {
55
- await _commands . AddModulesAsync ( Assembly . GetExecutingAssembly ( ) , scope . ServiceProvider ) ;
56
- }
57
-
53
+ using var scope = _services . CreateScope ( ) ;
54
+ await _commands . AddModulesAsync ( Assembly . GetExecutingAssembly ( ) , scope . ServiceProvider ) ;
55
+
58
56
}
59
57
60
58
public async Task HandleCommandAsync ( SocketMessage messageParam )
@@ -75,7 +73,8 @@ public async Task HandleCommandAsync(SocketMessage messageParam)
75
73
var prefix = ( await _guildPreferences . GetPreferencesAsync ( guildUser . Guild . Id ) ) . Prefix ;
76
74
77
75
// Determine if the message is a command based on the prefix and make sure no bots trigger commands
78
- if ( ! ( message . HasStringPrefix ( prefix , ref argPos ) || message . HasMentionPrefix ( _client . CurrentUser , ref argPos ) ) || message . Author . IsBot )
76
+ // TODO: Re add || message.Author.IsBot
77
+ if ( ! ( message . HasStringPrefix ( prefix , ref argPos ) || message . HasMentionPrefix ( _client . CurrentUser , ref argPos ) ) )
79
78
return ;
80
79
81
80
// Create a WebSocket-based command context based on the message
@@ -85,46 +84,44 @@ public async Task HandleCommandAsync(SocketMessage messageParam)
85
84
// created, along with the service provider for precondition checks.
86
85
87
86
// Create a scope to prevent leaks.
88
- using ( var scope = _services . CreateScope ( ) )
89
- {
90
- // TODO: Upgrade this to RunMode.Async
87
+ using var scope = _services . CreateScope ( ) ;
88
+ // TODO: Upgrade this to RunMode.Async
91
89
92
- // Keep in mind that result does not indicate a return value
93
- // rather an object stating if the command executed successfully.
94
- var result = await _commands . ExecuteAsync ( context , argPos , scope . ServiceProvider ) ;
90
+ // Keep in mind that result does not indicate a return value
91
+ // rather an object stating if the command executed successfully.
92
+ var result = await _commands . ExecuteAsync ( context , argPos , scope . ServiceProvider ) ;
95
93
96
- // Delete successful triggers.
97
- if ( result . IsSuccess )
94
+ // Delete successful triggers.
95
+ if ( result . IsSuccess )
96
+ {
97
+ try
98
98
{
99
- try
100
- {
101
- await message . DeleteAsync ( ) ;
102
- }
103
- catch ( Discord . Net . HttpException )
104
- {
105
- // Delete most likely failed due to no ManageMessages permission. Ignore regardless.
106
- }
99
+ await message . DeleteAsync ( ) ;
107
100
}
101
+ catch ( Discord . Net . HttpException )
102
+ {
103
+ // Delete most likely failed due to no ManageMessages permission. Ignore regardless.
104
+ }
105
+ }
108
106
109
- // Optionally, we may inform the user if the command fails
110
- // to be executed; however, this may not always be desired,
111
- // as it may clog up the request queue should a user spam a
112
- // command.
107
+ // Optionally, we may inform the user if the command fails
108
+ // to be executed; however, this may not always be desired,
109
+ // as it may clog up the request queue should a user spam a
110
+ // command.
113
111
114
- else if ( result . Error != CommandError . UnknownCommand )
112
+ else if ( result . Error != CommandError . UnknownCommand )
113
+ {
114
+ try
115
+ {
116
+ await context . Channel . SendMessageAsync ( embed : new EmbedBuilder ( )
117
+ . WithDefault ( result . ErrorReason , EmbedColor . Error ) . Build ( ) ) ;
118
+ }
119
+ catch ( Discord . Net . HttpException e )
115
120
{
116
- try
117
- {
118
- await context . Channel . SendMessageAsync ( embed : new EmbedBuilder ( )
119
- . WithDefault ( result . ErrorReason , EmbedColor . Error ) . Build ( ) ) ;
120
- }
121
- catch ( Discord . Net . HttpException e )
122
- {
123
- // 50013 occurs when bot cannot send embedded messages. All error reports use embeds.
124
- if ( e . DiscordCode == 50013 )
125
- await context . Channel . SendMessageAsync (
126
- "Bot requires guild permission EmbedLinks to function properly." ) ;
127
- }
121
+ // 50013 occurs when bot cannot send embedded messages. All error reports use embeds.
122
+ if ( e . DiscordCode == 50013 )
123
+ await context . Channel . SendMessageAsync (
124
+ "Bot requires guild permission EmbedLinks to function properly." ) ;
128
125
}
129
126
}
130
127
}
0 commit comments