Examples
Scripts are written in JavaScript and executed by the Go client using Goja.
Basic Command
Copy
ethone.on_command("hello", "Say hello", "hello [name]", function(ctx) {
var name = ctx.args.length > 0 ? ctx.args.join(" ") : ctx.author.username;
discord.send_message(ctx.channel.id, "Hello, " + name + "!");
});
Multi-Command Script
Copy
ethone.on_command("ping", "Check if bot is alive", "ping", function(ctx) {
discord.send_message(ctx.channel.id, "Pong!");
});
ethone.on_command("info", "Get server info", "info", function(ctx) {
var info = "Server: " + ctx.guild.name + "\n";
info += "Channel: #" + ctx.channel.name;
discord.send_message(ctx.channel.id, info);
});
ethone.on_command("help", "Show available commands", "help", function(ctx) {
discord.send_message(
ctx.channel.id,
"Commands: .ping, .info, .help"
);
});
Keyword Auto-Responder
Copy
discord.on_message = function(ctx) {
var content = ctx.content.toLowerCase();
if (content.includes("good morning")) {
discord.send_message(ctx.channel.id, "Good morning!");
}
if (content.includes("good night")) {
discord.send_message(ctx.channel.id, "Good night!");
}
};
Welcome Bot
Copy
discord.on_guild_member_add = function(ctx) {
var welcomeChannel = "YOUR_CHANNEL_ID_HERE";
var message = "Welcome <@" + ctx.user.id + "> to **" + ctx.guild.name + "**!\n";
message += "You're member #" + ctx.guild.member_count;
discord.send_message(welcomeChannel, message);
var metadata = "**New Member**\n";
metadata += "• Tag: " + ctx.user.tag + "\n";
metadata += "• ID: " + ctx.user.id + "\n";
metadata += "• Account Created: " + ctx.user.created_at + "\n";
metadata += "• Total Members: " + ctx.guild.member_count;
ethone.send_event("Member Joined", metadata, "info", undefined, {
text: ctx.guild.name,
icon: ctx.user.avatar_url
});
};
Message Logger
Copy
discord.on_message = function(ctx) {
var log = "=== Message ===\n";
log += "From: " + ctx.author.username + " (" + ctx.author.id + ")\n";
log += "Channel: #" + ctx.channel.name + " (" + ctx.channel.id + ")\n";
log += "Guild: " + ctx.guild.name + " (" + ctx.guild.id + ")\n";
log += "Content: " + ctx.content + "\n";
log += "===============";
ethone.log(log);
};
Delayed Response
Copy
ethone.on_command("countdown", "Count down from 3", "countdown", function(ctx) {
discord.send_message(ctx.channel.id, "3...");
ethone.sleep(1000);
discord.send_message(ctx.channel.id, "2...");
ethone.sleep(1000);
discord.send_message(ctx.channel.id, "1...");
ethone.sleep(1000);
discord.send_message(ctx.channel.id, "Blast off!");
});
API Integration
Copy
ethone.on_command("joke", "Get a random joke", "joke", function(ctx) {
try {
var response = discord.http_get("https://official-joke-api.appspot.com/random_joke");
if (response.status === 200) {
var joke = JSON.parse(response.data);
var text = joke.setup + "\n\n" + joke.punchline;
discord.send_message(ctx.channel.id, text);
} else {
discord.send_message(ctx.channel.id, "Failed to fetch joke!");
}
} catch (error) {
ethone.log("Error fetching joke: " + error);
discord.send_message(ctx.channel.id, "An error occurred!");
}
});
Command with Arguments
Copy
ethone.on_command("say", "Repeat a message", "say <message>", function(ctx) {
if (ctx.args.length === 0) {
discord.send_message(ctx.channel.id, "Usage: .say <message>");
return;
}
var text = ctx.args.join(" ");
discord.send_message(ctx.channel.id, text);
});
Auto-Delete Messages
Copy
var myMessages = [];
discord.on_message = function(ctx) {
if (ctx.author.id === ethone.user.id) {
myMessages.push({
channel: ctx.channel.id,
id: ctx.message.id
});
}
if (ctx.content === ".clear" && ctx.author.id === ethone.user.id) {
var count = myMessages.length;
for (var i = 0; i < myMessages.length; i++) {
discord.delete_message(myMessages[i].channel, myMessages[i].id);
}
myMessages = [];
ethone.log("Cleared " + count + " messages");
}
};
Error Handling
Copy
ethone.on_command("test", "Test command", "test", function(ctx) {
try {
discord.send_message(ctx.channel.id, "Test successful!");
} catch (error) {
ethone.log("Error: " + error);
try {
discord.send_message(ctx.channel.id, "An error occurred");
} catch (sendError) {
ethone.log("Failed to send error message: " + sendError);
}
}
});
Reaction Poll System
Copy
ethone.on_command("poll", "Create a poll", "poll <question>", function(ctx) {
if (ctx.args.length === 0) {
discord.send_message(ctx.channel.id, "Usage: .poll <question>");
return;
}
var question = ctx.args.join(" ");
var response = discord.send_message(ctx.channel.id, "Poll: " + question);
if (response) {
discord.add_reaction(ctx.channel.id, response.id, "👍");
discord.add_reaction(ctx.channel.id, response.id, "👎");
}
});
Auto-Moderation Bot
Copy
var blockedWords = ["spam", "scam", "free nitro"];
discord.on_message = function(ctx) {
if (ctx.author.bot) return;
var content = ctx.content.toLowerCase();
for (var i = 0; i < blockedWords.length; i++) {
if (content.includes(blockedWords[i])) {
discord.delete_message(ctx.channel.id, ctx.message.id);
var dm = discord.create_dm(ctx.author.id);
if (dm) {
discord.send_message(dm.id, "Your message was removed for containing blocked content.");
}
ethone.log("Deleted message from " + ctx.author.tag + " - Contains: " + blockedWords[i]);
return;
}
}
};
Role Reaction Menu
Copy
var roleMenuMsg = null;
var roleMap = {
"1": "GAMER_ROLE_ID",
"2": "ARTIST_ROLE_ID",
"3": "DEVELOPER_ROLE_ID"
};
ethone.on_command("rolemenu", "Setup role menu", "rolemenu", function(ctx) {
var text = "React to get roles:\n";
text += "1 - Gamer\n";
text += "2 - Artist\n";
text += "3 - Developer";
var msg = discord.send_message(ctx.channel.id, text);
if (msg) {
roleMenuMsg = msg.id;
ethone.set_value("role_menu_msg", msg.id);
discord.add_reaction(ctx.channel.id, msg.id, "1");
discord.add_reaction(ctx.channel.id, msg.id, "2");
discord.add_reaction(ctx.channel.id, msg.id, "3");
}
});
discord.on_reaction_add = function(ctx) {
if (!roleMenuMsg) {
roleMenuMsg = ethone.get_value("role_menu_msg");
}
if (ctx.message.id !== roleMenuMsg) return;
var roleId = roleMap[ctx.emoji.name];
if (roleId) {
discord.add_role(ctx.guild.id, ctx.user.id, roleId);
ethone.log("Added role to " + ctx.user.tag);
}
};
discord.on_reaction_remove = function(ctx) {
if (!roleMenuMsg) {
roleMenuMsg = ethone.get_value("role_menu_msg");
}
if (ctx.message.id !== roleMenuMsg) return;
var roleId = roleMap[ctx.emoji.name];
if (roleId) {
discord.remove_role(ctx.guild.id, ctx.user.id, roleId);
ethone.log("Removed role from " + ctx.user.tag);
}
};
Message History Scanner
Copy
ethone.on_command("scan", "Scan for keyword", "scan <keyword>", function(ctx) {
if (ctx.args.length === 0) {
discord.send_message(ctx.channel.id, "Usage: .scan <keyword>");
return;
}
var keyword = ctx.args[0].toLowerCase();
discord.send_typing(ctx.channel.id);
var messages = discord.get_messages(ctx.channel.id, 100);
var count = 0;
var authors = {};
for (var i = 0; i < messages.length; i++) {
var msg = messages[i];
if (msg.content.toLowerCase().includes(keyword)) {
count++;
var author = msg.author.username;
authors[author] = (authors[author] || 0) + 1;
}
}
var result = "Found '" + keyword + "' in " + count + " messages\n\n";
result += "Top users:\n";
for (var author in authors) {
result += author + ": " + authors[author] + " times\n";
}
discord.send_message(ctx.channel.id, result);
});
Advanced Welcome System
Copy
discord.on_guild_member_add = function(ctx) {
var dm = discord.create_dm(ctx.user.id);
if (dm) {
var welcome = "Welcome to " + ctx.guild.name + "!\n";
welcome += "You're member #" + ctx.guild.member_count + "\n";
welcome += "Read the rules in #rules before chatting.";
discord.send_message(dm.id, welcome);
}
var memberRole = ethone.get_value("member_role_id");
if (memberRole) {
discord.add_role(ctx.guild.id, ctx.user.id, memberRole);
}
var welcomeChannel = ethone.get_value("welcome_channel_id");
if (welcomeChannel) {
discord.send_message(welcomeChannel, "Welcome <@" + ctx.user.id + ">");
}
ethone.log("New member: " + ctx.user.tag);
};
Moderation Commands
Copy
ethone.on_command("kick", "Kick a member", "kick <userId> [reason]", function(ctx) {
if (ctx.args.length < 1) {
discord.send_message(ctx.channel.id, "Usage: .kick <userId> [reason]");
return;
}
var userId = ctx.args[0];
var reason = ctx.args.slice(1).join(" ") || "No reason provided";
if (discord.kick_member(ctx.guild.id, userId)) {
discord.send_message(ctx.channel.id, "Kicked <@" + userId + "> - " + reason);
ethone.log("Kicked " + userId + " - " + reason);
} else {
discord.send_message(ctx.channel.id, "Failed to kick user");
}
});
ethone.on_command("ban", "Ban a member", "ban <userId> [days] [reason]", function(ctx) {
if (ctx.args.length < 1) {
discord.send_message(ctx.channel.id, "Usage: .ban <userId> [days] [reason]");
return;
}
var userId = ctx.args[0];
var deleteMessageDays = parseInt(ctx.args[1]) || 0;
var reason = ctx.args.slice(2).join(" ") || "No reason provided";
if (discord.ban_member(ctx.guild.id, userId, deleteMessageDays)) {
discord.send_message(ctx.channel.id, "Banned <@" + userId + "> - " + reason);
ethone.log("Banned " + userId + " - " + reason);
} else {
discord.send_message(ctx.channel.id, "Failed to ban user");
}
});
ethone.on_command("unban", "Unban a member", "unban <userId>", function(ctx) {
if (ctx.args.length < 1) {
discord.send_message(ctx.channel.id, "Usage: .unban <userId>");
return;
}
var userId = ctx.args[0];
if (discord.unban_member(ctx.guild.id, userId)) {
discord.send_message(ctx.channel.id, "Unbanned <@" + userId + ">");
ethone.log("Unbanned " + userId);
} else {
discord.send_message(ctx.channel.id, "Failed to unban user");
}
});
Auto-Pin Important Messages
Copy
var adminIds = ["ADMIN_ID_1", "ADMIN_ID_2"];
var pinKeywords = ["announcement", "important", "urgent"];
discord.on_message = function(ctx) {
if (adminIds.includes(ctx.author.id) && ctx.content.startsWith("!pin")) {
discord.pin_message(ctx.channel.id, ctx.message.id);
ethone.log("Pinned message from " + ctx.author.tag);
return;
}
var content = ctx.content.toLowerCase();
for (var i = 0; i < pinKeywords.length; i++) {
if (content.includes(pinKeywords[i])) {
discord.pin_message(ctx.channel.id, ctx.message.id);
ethone.log("Auto-pinned message containing: " + pinKeywords[i]);
break;
}
}
};
Smart DM Responder
Copy
discord.on_message = function(ctx) {
if (!ctx.guild.id && ctx.author.id !== ethone.user.id) {
discord.send_typing(ctx.channel.id);
ethone.sleep(1000);
var response = "Thanks for your message! I'm currently away but will respond soon.\n";
response += "For urgent matters, contact: [email protected]";
discord.send_message(ctx.channel.id, response);
ethone.send_event("New DM", "From: " + ctx.author.tag + "\n" + ctx.content, "info");
ethone.log("Auto-responded to DM from " + ctx.author.tag);
}
};