Skip to content

Instantly share code, notes, and snippets.

@veeponym
Created February 15, 2023 13:10
Show Gist options
  • Save veeponym/a807840faa4e789e4ae7adb11cec77e1 to your computer and use it in GitHub Desktop.
Save veeponym/a807840faa4e789e4ae7adb11cec77e1 to your computer and use it in GitHub Desktop.
-- Define a ping object
local ping = {}
-- Define a function to register the commands
function ping:registerCommands(client, slash)
-- Define a slash command for ping
slash:registerCommand('ping', 'Get the bot latency', function(interaction)
-- Get the timestamp of the interaction
local timestamp = interaction.data.timestamp
-- Get the current time
local now = os.time()
-- Calculate the latency
local latency = now - timestamp
-- Reply with the latency
interaction:reply('Pong! The latency is ' .. latency .. ' seconds.')
end)
end
-- Define a function to unregister the commands
function ping:unregisterCommands(client, slash)
-- Unregister the slash command for ping
slash:unregisterCommand('ping')
end
-- Return the ping object
return ping
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment