A powerful Discord bot library for ComputerCraft: Tweaked that connects Minecraft computers to Discord.
- Overview
- Installation
- Quick Start
- Features
- Full Example
- Modular Architecture
- Contributing
- License
- Acknowledgements
Minecord is a comprehensive Lua library for CC: Tweaked that allows you to create Discord bots that run entirely inside Minecraft computers. Originally created as a basic message detection utility, Minecord has evolved into a full-featured Discord bot framework with support for:
- Message and slash commands
- Interactive components (buttons)
- Rich embeds and message formatting
- Reactions API
- User and channel management
- Message collectors
- File attachments
- And much more!
# Option 1: Using wget (recommended)
wget https://raw.githubusercontent.com/stealtech/minecord/main/Minecord.lua Minecord
# Option 2: Using pastebin
pastebin get JyjSq96A Minecord.lua- ComputerCraft: Tweaked (CC:T) version 1.95.0 or higher
- A Discord bot created through the Discord Developer Portal
- Bot token and application ID
local Discord = require("Minecord")
-- Set up event handlers
Discord.on("READY", function(data)
print("Bot is ready as " .. data.user.username .. "!")
-- Set the bot's activity
Discord.setActivity(0, "with CC:Tweaked") -- "Playing with CC:Tweaked"
end)
-- Handle messages
Discord.on("MESSAGE_CREATE", function(message)
if message.content then
print(message.author.username .. ": " .. message.content)
end
end)
-- Register a simple message command
Discord.registerCommand("ping", function(message, args)
Discord.sendMessage(message.channel_id, "Pong!")
end)
-- Enable command handling
Discord.handleCommands(true)
-- Start the bot (replace with your actual token, intents, and application ID)
Discord.login("YOUR_BOT_TOKEN", 33283, "YOUR_APPLICATION_ID")Subscribe to Discord gateway events:
Discord.on("MESSAGE_CREATE", function(message)
-- Handle new messages
end)
Discord.on("READY", function(data)
-- Bot is ready
end)
Discord.on("INTERACTION_CREATE", function(interaction)
-- Handle interactions
end)Message commands are triggered by a prefix (default: !) followed by the command name:
-- Set a custom prefix
Discord.setPrefix("?")
-- Register a command
Discord.registerCommand("echo", function(message, args)
local text = table.concat(args, " ")
if text ~= "" then
Discord.sendMessage(message.channel_id, text)
else
Discord.sendMessage(message.channel_id, "You didn't provide anything to echo!")
end
end)Slash commands are registered with Discord and appear in the Discord UI:
-- Define slash commands
local commands = {
{
name = "ping",
description = "Check the bot's latency",
type = 1
},
{
name = "echo",
description = "Echo back a message",
type = 1,
options = {
{
name = "message",
description = "The message to echo back",
type = 3, -- STRING
required = true
}
}
}
}
-- Register commands with Discord
Discord.registerApplicationCommands("YOUR_GUILD_ID", commands)
-- Handle the commands
Discord.onApplicationCommand("ping", function(interaction)
Discord.acknowledgeInteraction(interaction.id, interaction.token, {
content = "Pong!"
})
end)
Discord.onApplicationCommand("echo", function(interaction)
local message = interaction.data.options[1].value
Discord.acknowledgeInteraction(interaction.id, interaction.token, {
content = message
})
end)
-- Enable application command handling
Discord.handleApplicationCommands(true)Create rich embeds for your messages:
local embed = Discord.createEmbed({
title = "Hello World",
description = "This is an embed message",
color = 0x00AAFF, -- Blue color
footer = {
text = "Powered by CC:Tweaked"
},
thumbnail = {
url = "https://i.imgur.com/YhXwSHZ.png"
},
author = {
name = "Minecord Bot",
icon_url = "https://i.imgur.com/YhXwSHZ.png"
},
fields = {
{
name = "Field 1",
value = "This is a field",
inline = true
},
{
name = "Field 2",
value = "This is another field",
inline = true
}
},
timestamp = os.date("!%Y-%m-%dT%H:%M:%S.000Z")
})
Discord.sendMessage(channelId, "", { embeds = {embed} })Create interactive buttons and handle interactions:
-- Create different types of buttons
local primaryButton = Discord.createButton(1, "btn_primary", "Primary", nil, nil, false)
local secondaryButton = Discord.createButton(2, "btn_secondary", "Secondary")
local successButton = Discord.createButton(3, "btn_success", "Success")
local dangerButton = Discord.createButton(4, "btn_danger", "Danger")
local linkButton = Discord.createButton(5, nil, "Link", nil, "https://github.com")
-- Create an action row with buttons
local actionRow = Discord.createActionRow({
primaryButton, secondaryButton, successButton, dangerButton, linkButton
})
-- Send a message with components
Discord.sendComponentMessage(channelId, "Interactive buttons:", {actionRow})
-- Handle button interactions
Discord.onComponent("btn_primary", function(interaction)
Discord.acknowledgeInteraction(interaction.id, interaction.token, {
content = "You clicked the primary button!"
})
end)
-- Enable component handling
Discord.handleComponents(true)Edit and delete messages:
-- Send a message and get the message data
local messageData = Discord.sendMessage(channelId, "Initial content")
-- Edit a message
Discord.editMessage(channelId, messageData.id, "Updated content")
-- Edit a message with an embed
local embed = Discord.createEmbed({
title = "Updated Embed",
description = "This message was updated",
color = 0xFF0000
})
Discord.editEmbed(channelId, messageData.id, embed, "Updated content")
-- Delete a message
Discord.deleteMessage(channelId, messageData.id)Add and manage reactions on messages:
-- Add a reaction to a message
Discord.addReaction(channelId, messageId, "π")
-- Remove a reaction
Discord.removeReaction(channelId, messageId, "π")
-- Get users who reacted with a specific emoji
local reactors = Discord.getReactions(channelId, messageId, "π", { limit = 10 })
for _, user in ipairs(reactors) do
print(user.username .. " reacted")
endGet information about users and manage nicknames:
-- Get information about a user
local userData = Discord.getUser(userId)
print("Username: " .. userData.username)
-- Change a user's nickname in a guild
Discord.setNickname(guildId, userId, "New Nickname")
-- Change the bot's own nickname
Discord.setNickname(guildId, "@me", "Bot Nickname")Create and manage Discord channels:
-- Create a new text channel
local channelData = Discord.createChannel(guildId, "new-channel", {
type = 0, -- Text channel
topic = "A channel created via Minecord"
})
print("Created channel: " .. channelData.name)
-- Delete a channel
Discord.deleteChannel(channelId)Collect messages that match specific criteria:
-- Create a message collector
local collector = Discord.createMessageCollector({
channelId = channelId,
filter = function(message)
-- Only collect messages from a specific user
return message.author.id == userId
end,
max = 5, -- Collect up to 5 messages
time = 60, -- Collect for 60 seconds
collect = function(message)
print("Collected message: " .. message.content)
end,
["end"] = function(collected)
print("Collected " .. #collected .. " messages")
end
})Send messages with file attachments:
-- Send a message with file attachments
Discord.sendFileMessage(
channelId,
"Here are some files:",
{"disk/file1.txt", "disk/image.png"},
{
embeds = {
Discord.createEmbed({
title = "Files Attached",
description = "Check out these files"
})
}
}
)Set the bot's activity status:
-- Activity types:
-- 0 = Playing
-- 1 = Streaming
-- 2 = Listening
-- 3 = Watching
-- 4 = Custom
-- 5 = Competing
-- Set the bot to "Playing Minecraft"
Discord.setActivity(0, "Minecraft")
-- Set the bot to "Watching users"
Discord.setActivity(3, "users")
-- Set the bot to "Streaming" (with URL)
Discord.setActivity(1, "ComputerCraft", "https://twitch.tv/username")Measure the latency between your bot and Discord:
Discord.measurePing(function(pingTime)
print("Current ping: " .. pingTime .. "ms")
end)Minecord now supports a modular architecture for better organization and maintainability. The legacy single-file version will automatically fall back to the modular version when available.
Contributions are welcome! Feel free to open issues or submit pull requests to help improve Minecord.
This project is licensed under the MIT License - see the LICENSE file for details.
- Originally created as a basic message detection utility
- Enhanced with modern Discord API features in 2024
- Built for ComputerCraft: Tweaked
- Inspired by Discord.js