mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-22 03:05:16 +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,17 +63,31 @@ public class DiscordBot {
|
|||
SettingsLoadHandler();
|
||||
string mentionPrefix = $"{DiscordClient.CurrentUser.Mention} ";
|
||||
DiscordClient.MessageCreated += async (_, args) => {
|
||||
DiscordMessage msg = args.Message;
|
||||
if (msg.Content.StartsWith(Prefix)) {
|
||||
await msg.Channel.TriggerTypingAsync();
|
||||
await msg.RespondAsync(string.Join('\n',
|
||||
CommandHandler.GetResult(msg.Content[Prefix.Length..]).ReturnStrings));
|
||||
} else if (msg.Content.StartsWith(mentionPrefix)) {
|
||||
await msg.Channel.TriggerTypingAsync();
|
||||
await msg.RespondAsync(string.Join('\n',
|
||||
CommandHandler.GetResult(msg.Content[mentionPrefix.Length..]).ReturnStrings));
|
||||
try {
|
||||
DiscordMessage msg = args.Message;
|
||||
if (msg.Content.StartsWith(Prefix)) {
|
||||
await msg.Channel.TriggerTypingAsync();
|
||||
await msg.RespondAsync(string.Join('\n',
|
||||
CommandHandler.GetResult(msg.Content[Prefix.Length..]).ReturnStrings));
|
||||
} else if (msg.Content.StartsWith(mentionPrefix)) {
|
||||
await msg.Channel.TriggerTypingAsync();
|
||||
await msg.RespondAsync(string.Join('\n',
|
||||
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) {
|
||||
Logger.Error("Exception occurred in discord runner!");
|
||||
Logger.Error(e);
|
||||
|
|
Loading…
Reference in a new issue