add try catch

This commit is contained in:
Madpeter 2023-11-30 22:08:40 +00:00
parent 47de266915
commit 70eedefb37

View file

@ -716,12 +716,20 @@ namespace SecondBotEvents.Services
return reply.Id; return reply.Id;
} }
public ulong SendMessageToChannel(ulong serverid, ulong channelid, string message) public ulong? SendMessageToChannel(ulong serverid, ulong channelid, string message)
{ {
SocketGuild server = DiscordClient.GetGuild(serverid); try
ITextChannel channel = server.GetTextChannel(channelid); {
IMessage reply = channel.SendMessageAsync(message).GetAwaiter().GetResult(); SocketGuild server = DiscordClient.GetGuild(serverid);
return reply.Id; ITextChannel channel = server.GetTextChannel(channelid);
IMessage reply = channel.SendMessageAsync(message).GetAwaiter().GetResult();
return reply.Id;
}
catch (Exception e)
{
LogFormater.Crit("Discord service: Failed to send message to channel "+channelid.ToString()+" on server: "+serverid.ToString()+" because: "+e.Message);
return null;
}
} }
protected string GetChannelName(string input) protected string GetChannelName(string input)