Get up and start coding your first bot with silicord.
These are installed automatically when you install silicord via LuaRocks.
Run this in your terminal first to get silicord installed.
luarocks install silicord
Make a new file called bot.lua or whatever you like and paste this. This is a simple bot and you can expand it later.
local silicord = require("silicord")
local client = silicord.Connect({
token = "your bot token here",
prefix = "!"
})
client:CreateCommand("ping", function(message, args)
message:Reply("Pong")
end)
silicord.Run()
Head to the Discord Developer Portal, create an application, add a Bot, and copy the token. Paste it into your bot.lua.
Start your bot with a single command.
lua <filename>.lua
Your bot is now online. Type !ping in any channel it has access to and it will reply "Pong"!
The entry point for every silicord bot. Pass a config table with these fields:
| Field | Type | Required | Description |
|---|---|---|---|
token | string | ✅ yes | Your Discord bot token |
prefix | string | no | Command prefix (default: "!") |
app_id | string | no | Application ID — only needed for slash commands |
local client = silicord.Connect({
token = "your token",
prefix = "!",
app_id = "your application id" -- only needed for slash commands and presence updates
})
Here's a more complete bot showing prefix commands, slash commands, embeds, buttons, middleware, and events all together.
local silicord = require("silicord")
local client = silicord.Connect({
token = "your token here",
prefix = "!",
app_id = "your app id here"
})
-- Cooldown middleware
local cooldowns = {}
client:AddMiddleware(function(ctx, cmd, args)
local key = ctx.author.id .. ":" .. cmd
if os.time() - (cooldowns[key] or 0) < 3 then
ctx:Reply("Wait 3 seconds between commands.")
return false
end
cooldowns[key] = os.time()
end)
-- !ping
client:CreateCommand("ping", function(message, args)
message:Reply("Pong!")
end)
-- !vote (buttons)
client:CreateCommand("vote", function(message, args)
local row = silicord.ActionRow(
silicord.Button({ label = "Yes", style = "success", custom_id = "vote_yes" }),
silicord.Button({ label = "No", style = "danger", custom_id = "vote_no" })
)
message:Reply("Cast your vote!", nil, { row })
end)
client:CreateComponent("vote_yes", function(interaction)
interaction:Update("You voted Yes! ✅")
end)
-- /ping (slash)
client:CreateSlashCommand("ping", {
description = "Replies with pong"
}, function(interaction, args)
interaction:Reply("Pong!")
end)
silicord.Run()