Skip to main content

Commands API Reference

Command system API for Ethone custom scripts.

ethone.on_command()

Register a command with a callback function.

Syntax

ethone.on_command(name, description, usage, callback)

Parameters

ParameterTypeDescription
namestringCommand name without prefix (e.g., “hello” for “.hello”)
descriptionstringDescription of what the command does
usagestringUsage string shown in .custom command (e.g., “hello [name]“)
callbackfunctionFunction to execute when command is triggered

Context Object

The callback receives a ctx (context) object:
PropertyTypeDescription
ctx.commandstringThe command name that was triggered
ctx.argsstring[]Array of arguments passed to the command
ctx.messageMessageFull message object
ctx.guildGuildGuild/server object
ctx.channelChannelChannel object
ctx.authorAuthorMessage author object
Access IDs through context objects:
  • Use ctx.guild.id for guild ID
  • Use ctx.channel.id for channel ID
  • Use ctx.author.id for user ID

Guild Object Properties

PropertyTypeDescription
idstringGuild/server ID
namestringGuild name
icon_urlstringURL to guild icon image
owner_idstringUser ID of the server owner
member_countnumberTotal number of members
descriptionstringServer description
banner_urlstringURL to guild banner image
vanity_url_codestringCustom vanity URL code
verification_levelnumberVerification level (0-4)
premium_tiernumberNitro boost tier (0-3)
premium_subscription_countnumberNumber of boosts

Channel Object Properties

PropertyTypeDescription
idstringChannel ID
namestringChannel name
typenumberChannel type (0=text, 2=voice, 4=category, etc.)
topicstringChannel topic/description
positionnumberChannel position in the list
nsfwbooleanWhether channel is marked NSFW
parent_idstringCategory ID (if in a category)
guild_idstringGuild ID this channel belongs to

Author Object Properties

PropertyTypeDescription
idstringUser ID
usernamestringUsername
discriminatorstringUser discriminator
tagstringFull username with discriminator
avatar_urlstringURL to user’s avatar image
botbooleanWhether the user is a bot
global_namestringUser’s display name
banner_urlstringURL to user’s banner image
banner_colorstringUser’s banner color hex code
accent_colornumberUser’s accent color as integer

Message Object Properties

PropertyTypeDescription
idstringMessage ID
contentstringFull message content
authorAuthorAuthor object (same as ctx.author)
channel_idstringChannel ID
guild_idstringServer/guild ID
timestampstringISO 8601 timestamp
mentionsAuthor[]Array of mentioned users
attachmentsAttachment[]Array of file attachments
embedsEmbed[]Array of embed objects
reactionsReaction[]Array of reaction objects
pinnedbooleanWhether message is pinned

Example

ethone.on_command(
    "greet",              // name
    "Greet someone",      // description
    "greet <name>",       // usage
    function(ctx) {       // callback
        if (ctx.args.length === 0) {
            discord.send_message(ctx.channel.id, "Usage: .greet <name>");
            return;
        }
        var channelId = ctx.channel.id;
        var name = ctx.args.join(" ");
        var message = "Hello, " + name + "!";
        discord.send_message(channelId, message);
    }
);

ethone.on_command(
    "userinfo",            // name
    "Get user info",       // description
    "userinfo <userId>",   // usage
    function(ctx) {        // callback
        if (ctx.args.length === 0) {
            discord.send_message(ctx.channel.id, "Usage: .userinfo <userId>");
            return;
        }
        
        var userId = ctx.args[0];
        var user = discord.fetch_user(userId);
        if (user) {
            var channelId = ctx.channel.id;
            var info = "User: " + user.username + "\n";
            info += "ID: " + user.id + "\n";
            info += "Bot: " + (user.bot ? "Yes" : "No");
            discord.send_message(channelId, info);
        }
    }
);

Argument Parsing

Arguments are automatically parsed into ctx.args array.

Basic Arguments

ethone.on_command("greet", "Greet someone", "greet <name> [lastName]", function(ctx) {
    var name = ctx.args.join(" ");
    discord.send_message(ctx.channel.id, "Hello, " + name + "!");
});

Quoted Arguments

Arguments in quotes are treated as single values:
// User types: .say "hello world" test
// ctx.args = ["hello world", "test"]

// User types: .say one two three  
// ctx.args = ["one", "two", "three"]

Required Arguments

ethone.on_command("ban", "Ban a user", "ban <user> <reason>", function(ctx) {
    if (ctx.args.length < 2) {
        discord.send_message(ctx.channel.id, "Usage: .ban <user> <reason>");
        return;
    }
    
    var userId = ctx.args[0];
    var reason = ctx.args.slice(1).join(" ");
    discord.send_message(ctx.channel.id, "Banned: " + userId + " - " + reason);
});

Optional Arguments

ethone.on_command("repeat", "Repeat text", "repeat <text> [times]", function(ctx) {
    var times = 1;
    var text = ctx.args.join(" ");
    
    var lastArg = ctx.args[ctx.args.length - 1];
    if (!isNaN(lastArg)) {
        times = parseInt(lastArg);
        text = ctx.args.slice(0, -1).join(" ");
    }
    
    times = Math.min(times, 5);
    
    for (var i = 0; i < times; i++) {
        discord.send_message(ctx.channel.id, text);
    }
});