Skip to main content

Discord Namespace

The discord namespace provides functions to interact with Discord’s API.
Scripts are written in JavaScript and executed by the Go client using Goja.

discord.send_message()

Send a message to a Discord channel.

Syntax

discord.send_message(channelId, content)

Parameters

ParameterTypeDescription
channelIdstringThe Discord channel ID to send the message to
contentstringThe message content to send

Returns

void

Example

discord.on_message = function(ctx) {
    if (ctx.content === ".hello") {
        var channelId = ctx.channel.id;
        var content = "Hello, world!";
        discord.send_message(channelId, content);
    }
};

discord.edit_message()

Edit an existing Discord message.

Syntax

discord.edit_message(channelId, messageId, content)

Parameters

ParameterTypeDescription
channelIdstringThe Discord channel ID where the message is located
messageIdstringThe message ID to edit
contentstringThe new message content

Returns

void

Example

let lastMessageId = null;

discord.on_message = function(ctx) {
    if (ctx.content === ".edit") {
        if (lastMessageId) {
            var channelId = ctx.channel.id;
            var messageId = lastMessageId;
            var newContent = "This message was edited!";
            discord.edit_message(channelId, messageId, newContent);
        }
    }
    
    lastMessageId = ctx.message.id;
};

discord.delete_message()

Delete a Discord message.

Syntax

discord.delete_message(channelId, messageId)

Parameters

ParameterTypeDescription
channelIdstringThe Discord channel ID where the message is located
messageIdstringThe message ID to delete

Returns

void

Example

discord.on_message = function(ctx) {
    if (ctx.content.includes("badword")) {
        var channelId = ctx.channel.id;
        var messageId = ctx.message.id;
        discord.delete_message(channelId, messageId);
        ethone.log("Deleted message with bad word");
    }
};

discord.http_get()

Make an HTTP GET request to an external API.

Syntax

discord.http_get(url)

Parameters

ParameterTypeDescription
urlstringThe URL to make a GET request to

Returns

HttpResponse - An object containing:
PropertyTypeDescription
statusnumberHTTP status code (e.g., 200, 404)
datastringResponse body as a string
headersobjectResponse headers

Example

ethone.on_command("weather", "Get weather for a city", "weather <city>", function(ctx) {
    if (ctx.args.length === 0) {
        discord.send_message(ctx.channel.id, "Usage: .weather <city>");
        return;
    }
    
    var city = ctx.args.join(" ");
    
    try {
        var response = discord.http_get(
            "https://api.weather.com/v1/city/" + city
        );
        
        if (response.status === 200) {
            var data = JSON.parse(response.data);
            discord.send_message(
                ctx.channel.id,
                "Weather in " + city + ": " + data.temperature
            );
        } else {
            discord.send_message(
                ctx.channel.id,
                "Failed to get weather data"
            );
        }
    } catch (error) {
        ethone.log("HTTP request failed: " + error);
        discord.send_message(ctx.channel.id, "An error occurred!");
    }
});

Notes

  • Only GET requests are supported
  • Be mindful of rate limits on external APIs
  • Always handle errors with try/catch
  • Response data is always a string - use JSON.parse() if needed

discord.fetch_message()

Fetch a Discord message by its ID.

Syntax

discord.fetch_message(channelId, messageId)

Parameters

ParameterTypeDescription
channelIdstringChannel ID where the message is
messageIdstringMessage ID to fetch

Returns

Message or null if not found

Example

ethone.on_command("quote", "Quote a message", "quote <messageId>", function(ctx) {
    if (ctx.args.length < 1) {
        discord.send_message(ctx.channel.id, "Usage: .quote <messageId>");
        return;
    }
    
    var msg = discord.fetch_message(ctx.channel.id, ctx.args[0]);
    if (msg) {
        discord.send_message(ctx.channel.id, msg.author + ": " + msg.content);
    } else {
        discord.send_message(ctx.channel.id, "Message not found");
    }
});

discord.fetch_guild()

Fetch a Discord guild/server by its ID.

Syntax

discord.fetch_guild(guildId)

Parameters

ParameterTypeDescription
guildIdstringGuild ID to fetch

Returns

Guild or null if not found

Example

ethone.on_command("guildinfo", "Get info about a guild", "guildinfo", function(ctx) {
    var guild = discord.fetch_guild(ctx.guild.id);
    if (guild) {
        var info = "Guild: " + guild.name + "\n";
        info += "Members: " + guild.member_count + "\n";
        info += "Owner ID: " + guild.owner_id;
        discord.send_message(ctx.channel.id, info);
    }
});

discord.fetch_channel()

Fetch a Discord channel by its ID.

Syntax

discord.fetch_channel(channelId)

Parameters

ParameterTypeDescription
channelIdstringChannel ID to fetch

Returns

Channel or null if not found

Example

ethone.on_command("channelinfo", "Get channel info", "channelinfo", function(ctx) {
    var channel = discord.fetch_channel(ctx.channel.id);
    if (channel) {
        var info = "Channel: #" + channel.name + "\n";
        info += "Type: " + channel.type + "\n";
        info += "Topic: " + (channel.topic || "None");
        discord.send_message(ctx.channel.id, info);
    }
});

discord.fetch_user()

Fetch a Discord user by their ID.

Syntax

discord.fetch_user(userId)

Parameters

ParameterTypeDescription
userIdstringUser ID to fetch

Returns

Author or null if not found

Example

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

discord.add_reaction()

Add a reaction to a message.

Syntax

discord.add_reaction(channelId, messageId, emoji)

Parameters

ParameterTypeDescription
channelIdstringChannel ID
messageIdstringMessage ID
emojistringEmoji (e.g., “+1” or custom emoji name)

Returns

boolean - true if successful

Example

ethone.on_command("react", "Add reaction", "react <messageId> <emoji>", function(ctx) {
    if (ctx.args.length < 2) {
        discord.send_message(ctx.channel.id, "Usage: .react <messageId> <emoji>");
        return;
    }
    
    if (discord.add_reaction(ctx.channel.id, ctx.args[0], ctx.args[1])) {
        discord.send_message(ctx.channel.id, "Reaction added!");
    }
});

discord.remove_reaction()

Remove a reaction from a message.

Syntax

discord.remove_reaction(channelId, messageId, emoji, userId)

Parameters

ParameterTypeDescription
channelIdstringChannel ID
messageIdstringMessage ID
emojistringEmoji to remove
userIdstringUser ID (optional, defaults to self)

Returns

boolean - true if successful

Example

// Remove your own reaction
discord.remove_reaction(ctx.channel.id, messageId, "+1");

// Remove someone else's reaction
discord.remove_reaction(ctx.channel.id, messageId, "+1", userId);

discord.send_typing()

Send typing indicator in a channel.

Syntax

discord.send_typing(channelId)

Parameters

ParameterTypeDescription
channelIdstringChannel ID

Returns

boolean - true if successful

Example

ethone.on_command("think", "Show typing", "think", function(ctx) {
    discord.send_typing(ctx.channel.id);
    ethone.sleep(3000);
    discord.send_message(ctx.channel.id, "Done thinking!");
});

discord.pin_message()

Pin a message in a channel.

Syntax

discord.pin_message(channelId, messageId)

Parameters

ParameterTypeDescription
channelIdstringChannel ID
messageIdstringMessage ID to pin

Returns

boolean - true if successful

Example

ethone.on_command("pin", "Pin message", "pin <messageId>", function(ctx) {
    if (ctx.args.length < 1) {
        discord.send_message(ctx.channel.id, "Usage: .pin <messageId>");
        return;
    }
    
    if (discord.pin_message(ctx.channel.id, ctx.args[0])) {
        discord.send_message(ctx.channel.id, "Message pinned!");
    }
});

discord.unpin_message()

Unpin a message in a channel.

Syntax

discord.unpin_message(channelId, messageId)

Parameters

ParameterTypeDescription
channelIdstringChannel ID
messageIdstringMessage ID to unpin

Returns

boolean - true if successful

discord.add_role()

Add a role to a member.

Syntax

discord.add_role(guildId, userId, roleId)

Parameters

ParameterTypeDescription
guildIdstringGuild ID
userIdstringUser ID
roleIdstringRole ID to add

Returns

boolean - true if successful

Example

ethone.on_command("giverole", "Give role", "giverole <userId> <roleId>", function(ctx) {
    if (ctx.args.length < 2) {
        discord.send_message(ctx.channel.id, "Usage: .giverole <userId> <roleId>");
        return;
    }
    
    if (discord.add_role(ctx.guild.id, ctx.args[0], ctx.args[1])) {
        discord.send_message(ctx.channel.id, "Role added!");
    }
});

discord.remove_role()

Remove a role from a member.

Syntax

discord.remove_role(guildId, userId, roleId)

Parameters

ParameterTypeDescription
guildIdstringGuild ID
userIdstringUser ID
roleIdstringRole ID to remove

Returns

boolean - true if successful

discord.kick_member()

Kick a member from a guild.

Syntax

discord.kick_member(guildId, userId)

Parameters

ParameterTypeDescription
guildIdstringGuild ID
userIdstringUser ID to kick

Returns

boolean - true if successful

Example

ethone.on_command("kick", "Kick member", "kick <userId>", function(ctx) {
    if (ctx.args.length < 1) {
        discord.send_message(ctx.channel.id, "Usage: .kick <userId>");
        return;
    }
    
    if (discord.kick_member(ctx.guild.id, ctx.args[0])) {
        discord.send_message(ctx.channel.id, "Member kicked!");
    }
});

discord.ban_member()

Ban a member from a guild.

Syntax

discord.ban_member(guildId, userId, deleteMessageDays)

Parameters

ParameterTypeDescription
guildIdstringGuild ID
userIdstringUser ID to ban
deleteMessageDaysnumberDays of messages to delete (0-7, optional)

Returns

boolean - true if successful

Example

ethone.on_command("ban", "Ban member", "ban <userId> [days]", function(ctx) {
    if (ctx.args.length < 1) {
        discord.send_message(ctx.channel.id, "Usage: .ban <userId> [days]");
        return;
    }
    
    var days = ctx.args.length > 1 ? parseInt(ctx.args[1]) : 0;
    if (discord.ban_member(ctx.guild.id, ctx.args[0], days)) {
        discord.send_message(ctx.channel.id, "Member banned!");
    }
});

discord.unban_member()

Unban a member from a guild.

Syntax

discord.unban_member(guildId, userId)

Parameters

ParameterTypeDescription
guildIdstringGuild ID
userIdstringUser ID to unban

Returns

boolean - true if successful

discord.leave_guild()

Leave a guild/server.

Syntax

discord.leave_guild(guildId)

Parameters

ParameterTypeDescription
guildIdstringGuild ID to leave

Returns

boolean - true if successful

discord.create_dm()

Create a DM channel with a user.

Syntax

discord.create_dm(userId)

Parameters

ParameterTypeDescription
userIdstringUser ID

Returns

DM channel object with id property, or null if failed

Example

ethone.on_command("dm", "Send DM", "dm <userId> <message>", function(ctx) {
    if (ctx.args.length < 2) {
        discord.send_message(ctx.channel.id, "Usage: .dm <userId> <message>");
        return;
    }
    
    var dm = discord.create_dm(ctx.args[0]);
    if (dm) {
        var message = ctx.args.slice(1).join(" ");
        discord.send_message(dm.id, message);
        discord.send_message(ctx.channel.id, "DM sent!");
    }
});

discord.get_messages()

Get recent messages from a channel.

Syntax

discord.get_messages(channelId, limit)

Parameters

ParameterTypeDescription
channelIdstringChannel ID
limitnumberNumber of messages (max 100, optional, default: 100)

Returns

Array of message objects

Example

ethone.on_command("recent", "Get recent messages", "recent [limit]", function(ctx) {
    var limit = ctx.args.length > 0 ? parseInt(ctx.args[0]) : 10;
    var messages = discord.get_messages(ctx.channel.id, limit);
    
    discord.send_message(ctx.channel.id, "Retrieved " + messages.length + " messages");
});

discord.create_channel()

Create a new channel in a guild.

Syntax

discord.create_channel(guildId, name, type, options)

Parameters

ParameterTypeDescription
guildIdstringGuild ID
namestringChannel name
typenumberChannel type (0=text, 2=voice, 4=category, 5=news, optional, default: 0)
optionsobjectOptional settings (topic, nsfw, parent_id, position)

Returns

Channel object or null if failed

Example

ethone.on_command("createchannel", "Create channel", "createchannel <name>", function(ctx) {
    if (ctx.args.length < 1) {
        discord.send_message(ctx.channel.id, "Usage: .createchannel <name>");
        return;
    }
    
    var name = ctx.args.join("-");
    var channel = discord.create_channel(ctx.guild.id, name, 0, {
        topic: "Created by bot",
        nsfw: false
    });
    
    if (channel) {
        discord.send_message(ctx.channel.id, "Created channel: #" + channel.name);
    } else {
        discord.send_message(ctx.channel.id, "Failed to create channel");
    }
});

discord.edit_channel()

Edit an existing channel.

Syntax

discord.edit_channel(channelId, options)

Parameters

ParameterTypeDescription
channelIdstringChannel ID to edit
optionsobjectProperties to update (name, topic, nsfw, position, parent_id)

Returns

boolean - true if successful

Example

ethone.on_command("editchannel", "Edit channel", "editchannel <topic>", function(ctx) {
    if (ctx.args.length < 1) {
        discord.send_message(ctx.channel.id, "Usage: .editchannel <topic>");
        return;
    }
    
    var topic = ctx.args.join(" ");
    if (discord.edit_channel(ctx.channel.id, { topic: topic })) {
        discord.send_message(ctx.channel.id, "Channel updated!");
    } else {
        discord.send_message(ctx.channel.id, "Failed to update channel");
    }
});

discord.delete_channel()

Delete a channel.

Syntax

discord.delete_channel(channelId)

Parameters

ParameterTypeDescription
channelIdstringChannel ID to delete

Returns

boolean - true if successful

Example

ethone.on_command("deletechannel", "Delete channel", "deletechannel <channelId>", function(ctx) {
    if (ctx.args.length < 1) {
        discord.send_message(ctx.channel.id, "Usage: .deletechannel <channelId>");
        return;
    }
    
    if (discord.delete_channel(ctx.args[0])) {
        discord.send_message(ctx.channel.id, "Channel deleted!");
    } else {
        discord.send_message(ctx.channel.id, "Failed to delete channel");
    }
});

discord.create_role()

Create a new role in a guild.

Syntax

discord.create_role(guildId, options)

Parameters

ParameterTypeDescription
guildIdstringGuild ID
optionsobjectOptional role properties (name, color, hoist, mentionable)

Returns

Role object or null if failed

Example

ethone.on_command("createrole", "Create role", "createrole <name>", function(ctx) {
    if (ctx.args.length < 1) {
        discord.send_message(ctx.channel.id, "Usage: .createrole <name>");
        return;
    }
    
    var role = discord.create_role(ctx.guild.id, {
        name: ctx.args.join(" "),
        color: 0xFF5733,
        hoist: true,
        mentionable: true
    });
    
    if (role) {
        discord.send_message(ctx.channel.id, "Created role: " + role.name);
    } else {
        discord.send_message(ctx.channel.id, "Failed to create role");
    }
});

discord.edit_role()

Edit an existing role.

Syntax

discord.edit_role(guildId, roleId, options)

Parameters

ParameterTypeDescription
guildIdstringGuild ID
roleIdstringRole ID to edit
optionsobjectProperties to update (name, color, hoist, mentionable, position)

Returns

boolean - true if successful

Example

ethone.on_command("editrole", "Edit role", "editrole <roleId> <name>", function(ctx) {
    if (ctx.args.length < 2) {
        discord.send_message(ctx.channel.id, "Usage: .editrole <roleId> <name>");
        return;
    }
    
    var roleId = ctx.args[0];
    var name = ctx.args.slice(1).join(" ");
    
    if (discord.edit_role(ctx.guild.id, roleId, { name: name, color: 0x00FF00 })) {
        discord.send_message(ctx.channel.id, "Role updated!");
    } else {
        discord.send_message(ctx.channel.id, "Failed to update role");
    }
});

discord.delete_role()

Delete a role from a guild.

Syntax

discord.delete_role(guildId, roleId)

Parameters

ParameterTypeDescription
guildIdstringGuild ID
roleIdstringRole ID to delete

Returns

boolean - true if successful

Example

ethone.on_command("deleterole", "Delete role", "deleterole <roleId>", function(ctx) {
    if (ctx.args.length < 1) {
        discord.send_message(ctx.channel.id, "Usage: .deleterole <roleId>");
        return;
    }
    
    if (discord.delete_role(ctx.guild.id, ctx.args[0])) {
        discord.send_message(ctx.channel.id, "Role deleted!");
    } else {
        discord.send_message(ctx.channel.id, "Failed to delete role");
    }
});

discord.edit_member()

Edit a guild member (nickname, roles, etc.).

Syntax

discord.edit_member(guildId, userId, options)

Parameters

ParameterTypeDescription
guildIdstringGuild ID
userIdstringUser ID to edit
optionsobjectProperties to update (nick, roles)

Returns

boolean - true if successful

Example

ethone.on_command("setnick", "Set nickname", "setnick <userId> <nickname>", function(ctx) {
    if (ctx.args.length < 2) {
        discord.send_message(ctx.channel.id, "Usage: .setnick <userId> <nickname>");
        return;
    }
    
    var userId = ctx.args[0];
    var nick = ctx.args.slice(1).join(" ");
    
    if (discord.edit_member(ctx.guild.id, userId, { nick: nick })) {
        discord.send_message(ctx.channel.id, "Nickname updated!");
    } else {
        discord.send_message(ctx.channel.id, "Failed to update nickname");
    }
});