From ab5ed16c18e3500d043cf13e2efae71761e59f07 Mon Sep 17 00:00:00 2001
From: tommy <thefamousdoge@hotmail.com>
Date: Wed, 10 Jul 2024 16:20:33 -0400
Subject: [PATCH] let's add a little bit of protection

---
 src/SlashCommands/User.lua |  3 +++
 src/main.lua               | 13 ++++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/SlashCommands/User.lua b/src/SlashCommands/User.lua
index 7f4081b..0533487 100644
--- a/src/SlashCommands/User.lua
+++ b/src/SlashCommands/User.lua
@@ -94,6 +94,9 @@ local function Callback(Interaction, Command, Args)
 			user_info = API:GetRobloxInfoFromDiscordId(user.id)
 		end
 	end
+    if not user_info.id then
+        return error('stop doing that')
+    end
 
     local description = user_info.description=='' and 'This user has no description' or user_info.description
     -- table.foreach(user_info,print)
diff --git a/src/main.lua b/src/main.lua
index e80d873..027d876 100644
--- a/src/main.lua
+++ b/src/main.lua
@@ -21,24 +21,31 @@ Client:on('ready', function()
     UserCommandCollector:Publish(Client)
 end)
 
+local function RunCallback(Callback, Interaction, Command, Args)
+    local Success, Return = pcall(Callback, Interaction, Command, Args)
+    if not Success then
+        Interaction:reply('Error encountered when trying to run command: '..Return, true)
+    end
+end
+
 Client:on('slashCommand', function(Interaction, Command, Args)
     local SlashCommand = SlashCommandCollector:Get(Command.name)
     if SlashCommand then
-        SlashCommand.Callback(Interaction, Command, Args)
+        RunCallback(SlashCommand.Callback, Interaction, Command, Args)
     end
 end)
 
 Client:on('messageCommand', function(Interaction, Command, Message)
     local MessageCommand = MessageCommandCollector:Get(Command.name)
     if MessageCommand then
-        MessageCommand.Callback(Interaction, Command, Message)
+        RunCallback(MessageCommand.Callback, Interaction, Command, Message)
     end
 end)
 
 Client:on('userCommand', function(Interaction, Command, Member)
     local UserCommand = UserCommandCollector:Get(Command.name)
     if UserCommand then
-        UserCommand.Callback(Interaction, Command, Member)
+        RunCallback(UserCommand.Callback, Interaction, Command, Member)
     end
 end)