mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-22 11:15:15 +00:00
Try/catch bot msg sending and add exception handlers
This commit is contained in:
parent
e9136704c1
commit
22a8e91f85
1 changed files with 23 additions and 9 deletions
|
@ -63,6 +63,7 @@ public class DiscordBot {
|
||||||
SettingsLoadHandler();
|
SettingsLoadHandler();
|
||||||
string mentionPrefix = $"{DiscordClient.CurrentUser.Mention} ";
|
string mentionPrefix = $"{DiscordClient.CurrentUser.Mention} ";
|
||||||
DiscordClient.MessageCreated += async (_, args) => {
|
DiscordClient.MessageCreated += async (_, args) => {
|
||||||
|
try {
|
||||||
DiscordMessage msg = args.Message;
|
DiscordMessage msg = args.Message;
|
||||||
if (msg.Content.StartsWith(Prefix)) {
|
if (msg.Content.StartsWith(Prefix)) {
|
||||||
await msg.Channel.TriggerTypingAsync();
|
await msg.Channel.TriggerTypingAsync();
|
||||||
|
@ -73,6 +74,19 @@ public class DiscordBot {
|
||||||
await msg.RespondAsync(string.Join('\n',
|
await msg.RespondAsync(string.Join('\n',
|
||||||
CommandHandler.GetResult(msg.Content[mentionPrefix.Length..]).ReturnStrings));
|
CommandHandler.GetResult(msg.Content[mentionPrefix.Length..]).ReturnStrings));
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logger.Error(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
DiscordClient.ClientErrored += (_, args) => {
|
||||||
|
Logger.Error("Discord client caught an error in handler!");
|
||||||
|
Logger.Error(args.Exception);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
};
|
||||||
|
DiscordClient.SocketErrored += (_, args) => {
|
||||||
|
Logger.Error("Discord client caught an error on socket!");
|
||||||
|
Logger.Error(args.Exception);
|
||||||
|
return Task.CompletedTask;
|
||||||
};
|
};
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.Error("Exception occurred in discord runner!");
|
Logger.Error("Exception occurred in discord runner!");
|
||||||
|
|
Loading…
Reference in a new issue