### Install Eris Discord Wrapper Source: https://github.com/abalabahaha/eris/blob/dev/README.md Installs the Eris library for Node.js. For voice support, additional dependencies like Python and a C++ compiler are required, and the --no-optional flag should be removed during installation. ```bash npm install --no-optional eris ``` -------------------------------- ### Eris Ping Pong Bot Example (Node.js) Source: https://github.com/abalabahaha/eris/blob/dev/README.md A basic Node.js example demonstrating how to create a Discord bot using the Eris library. The bot listens for '!ping' and '!pong' messages and responds accordingly. It requires a Discord bot token and specific intents. ```javascript const Eris = require("eris"); // Replace TOKEN with your bot account's token const bot = new Eris("Bot TOKEN", { intents: [ "guildMessages" ] }); bot.on("ready", () => { // When the bot is ready console.log("Ready!"); // Log "Ready!" }); bot.on("error", (err) => { console.error(err); // or your preferred logger }); bot.on("messageCreate", (msg) => { // When a message is created if(msg.content === "!ping") { // If the message content is "!ping" bot.createMessage(msg.channel.id, "Pong!"); // Send a message in the same channel with "Pong!" } else if(msg.content === "!pong") { // Otherwise, if the message is "!pong" bot.createMessage(msg.channel.id, "Ping!"); // Respond with "Ping!" } }); bot.connect(); // Get the bot to connect to Discord ``` -------------------------------- ### Eris Command Framework Setup and Usage (JavaScript) Source: https://context7.com/abalabahaha/eris/llms.txt Demonstrates how to set up and use the CommandClient in Eris for handling bot commands. It covers basic command registration, commands with functions, async commands with permissions, and subcommand registration. This framework simplifies command management with features like prefixes, descriptions, and help commands. ```javascript const Eris = require("eris"); // Create a CommandClient instead of a regular Client const bot = new Eris.CommandClient("Bot TOKEN", { intents: ["guilds", "guildMessages", "messageContent"] }, { prefix: "!", // Command prefix description: "My awesome bot", // Bot description for help command owner: "Your Name", // Bot owner defaultHelpCommand: true // Enable built-in help command }); bot.on("ready", () => { console.log("Ready!"); }); // Register a simple command bot.registerCommand("ping", "Pong!", { description: "Check if the bot is alive", fullDescription: "Use this command to verify the bot is responding to commands." }); // Register a command with a function bot.registerCommand("say", (msg, args) => { if (args.length === 0) return "Please provide something to say!"; return args.join(" "); }, { description: "Make the bot say something", usage: "", argsRequired: true, guildOnly: true }); // Register a command with async function and permissions bot.registerCommand("kick", async (msg, args) => { if (!args[0]) return "Please mention a user to kick"; const member = msg.mentions[0]; if (!member) return "User not found"; try { await bot.kickGuildMember(msg.guildID, member.id, "Kicked by command"); return `Kicked ${member.username}`; } catch (err) { return `Failed to kick: ${err.message}`; } }, { description: "Kick a member", usage: "<@user>", guildOnly: true, requirements: { permissions: { kickMembers: true } }, permissionMessage: "You need kick permissions to use this command." }); // Register a command with subcommands const infoCommand = bot.registerCommand("info", "Use `!info user` or `!info server`", { description: "Get information" }); infoCommand.registerSubcommand("user", (msg, args) => { const user = msg.mentions[0] || msg.author; return `User: ${user.username}#${user.discriminator}\nID: ${user.id}\nCreated: ${new Date(user.createdAt).toDateString()}`; }, { description: "Get user info" }); infoCommand.registerSubcommand("server", (msg) => { const guild = msg.channel.guild; return `Server: ${guild.name}\nMembers: ${guild.memberCount}\nOwner: <@${guild.ownerID}>`; }, { description: "Get server info", guildOnly: true }); bot.on("error", (err) => console.error(err)); bot.connect(); ``` -------------------------------- ### Send Rich Embed Messages with Eris Source: https://context7.com/abalabahaha/eris/llms.txt Shows how to send rich embed messages using Eris. This example demonstrates creating an embed with a title, description, color, author information, thumbnail, fields (inline and full-width), image, footer, and a timestamp. It is triggered by a '!embed' command. ```javascript const Eris = require("eris"); const bot = new Eris("Bot TOKEN", { intents: ["guilds", "guildMessages", "messageContent"] }); bot.on("messageCreate", async (msg) => { if (msg.content === "!embed") { await bot.createMessage(msg.channel.id, { embeds: [{ title: "Embed Title", description: "This is the embed description with **markdown** support.", color: 0x00AE86, // Hex color as integer author: { name: msg.author.username, icon_url: msg.author.avatarURL }, thumbnail: { url: "https://example.com/thumbnail.png" }, fields: [ { name: "Field 1", value: "Field value", inline: true }, { name: "Field 2", value: "Another value", inline: true }, { name: "Full Width Field", value: "This field takes the full width", inline: false } ], image: { url: "https://example.com/image.png" }, footer: { text: "Footer text", icon_url: "https://example.com/footer-icon.png" }, timestamp: new Date().toISOString() }] }); } }); bot.on("error", (err) => console.error(err)); bot.connect(); ``` -------------------------------- ### GET /users/@me/channels Source: https://context7.com/abalabahaha/eris/llms.txt Retrieves or creates a direct message channel with a specific user to enable private communication. ```APIDOC ## GET /users/@me/channels ### Description Retrieves a DM channel with a specific user. If a channel does not exist, it creates one. ### Method GET ### Endpoint /users/@me/channels ### Parameters #### Path Parameters - **userID** (string) - Required - The ID of the user to open a DM with. ### Request Example ```javascript const dmChannel = await bot.getDMChannel(userID); ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier of the DM channel. #### Response Example { "id": "123456789012345678", "type": 1 } ``` -------------------------------- ### Send Direct Message with Eris Source: https://context7.com/abalabahaha/eris/llms.txt This JavaScript code snippet demonstrates how to send a direct message to a specific user using the Eris library. It includes error handling for DM channel creation and message sending. The example also shows how to trigger this functionality via a chat command and how to listen for incoming DMs. ```javascript const Eris = require("eris"); const bot = new Eris("Bot TOKEN", { intents: ["guilds", "directMessages", "guildMessages", "messageContent"] }); bot.on("ready", () => { console.log("Ready!"); }); // Send a DM to a user async function sendDM(userID, message) { try { // Get or create the DM channel const dmChannel = await bot.getDMChannel(userID); // Send a message to the DM channel await bot.createMessage(dmChannel.id, message); return true; } catch (err) { console.error("Failed to send DM:", err.message); return false; } } bot.on("messageCreate", async (msg) => { if (msg.content === "!dm") { const success = await sendDM(msg.author.id, { content: "Hello! This is a direct message from the bot.", embeds: [{ title: "DM Embed", description: "You can send embeds in DMs too!" }] }); if (success) { await bot.createMessage(msg.channel.id, "Check your DMs!"); } else { await bot.createMessage(msg.channel.id, "I couldn't send you a DM. Make sure your DMs are open!"); } } }); // Listen for DM messages bot.on("messageCreate", (msg) => { // Check if the message is in a DM channel if (!msg.guildID) { console.log(`DM from ${msg.author.username}: ${msg.content}`); } }); bot.on("error", (err) => console.error(err)); bot.connect(); ``` -------------------------------- ### Client Initialization Source: https://context7.com/abalabahaha/eris/llms.txt Initializes the Eris bot client with necessary intents and configuration. ```APIDOC ## Client Initialization ### Description Sets up the Eris Client instance with authentication, gateway intents, and connection settings. ### Method N/A (Constructor) ### Parameters #### Request Body - **token** (string) - Required - The bot token prefixed with "Bot ". - **options** (object) - Required - Configuration object including intents, autoreconnect, and sharding settings. ### Request Example { "token": "Bot YOUR_TOKEN", "options": { "intents": ["guilds", "guildMessages"], "autoreconnect": true } } ``` -------------------------------- ### Handle Messages and Create Basic Replies with Eris Source: https://context7.com/abalabahaha/eris/llms.txt Demonstrates how to handle incoming messages and send basic text replies using the Eris library. It includes logic to ignore bot messages, respond to a '!ping' command with 'Pong!', reply to a '!hello' command, and send messages with controlled mentions using `createMessage`. ```javascript const Eris = require("eris"); const bot = new Eris("Bot TOKEN", { intents: ["guilds", "guildMessages", "messageContent"] }); bot.on("ready", () => { console.log("Ready!"); }); bot.on("messageCreate", async (msg) => { // Ignore bot messages if (msg.author.bot) return; // Simple ping command if (msg.content === "!ping") { await bot.createMessage(msg.channel.id, "Pong!"); } // Reply to a message if (msg.content === "!hello") { await bot.createMessage(msg.channel.id, { content: `Hello, ${msg.author.username}!`, messageReference: { messageID: msg.id // This creates a reply } }); } // Send a message with allowed mentions control if (msg.content.startsWith("!say ")) { const text = msg.content.slice(5); await bot.createMessage(msg.channel.id, { content: text, allowedMentions: { everyone: false, roles: false, users: false } }); } }); bot.on("error", (err) => console.error(err)); bot.connect(); ``` -------------------------------- ### Eris Voice Connections and Audio Playback (JavaScript) Source: https://context7.com/abalabahaha/eris/llms.txt Illustrates how to establish voice connections in Eris and play audio files. This snippet shows joining a voice channel, playing an MP3 file, and handling connection events like 'end' and 'error'. It also includes functionality to leave voice channels and stop playback. ```javascript const Eris = require("eris"); const bot = new Eris("Bot TOKEN", { intents: ["guilds", "guildMessages", "guildVoiceStates", "messageContent"] }); bot.on("ready", () => { console.log("Ready!"); }); bot.on("messageCreate", async (msg) => { if (msg.content === "!join") { if (!msg.member?.voiceState?.channelID) { return bot.createMessage(msg.channel.id, "You must be in a voice channel!"); } try { const connection = await bot.joinVoiceChannel(msg.member.voiceState.channelID, { selfDeaf: true, selfMute: false }); await bot.createMessage(msg.channel.id, "Joined voice channel!"); // Play an audio file connection.play("audio.mp3"); connection.on("end", () => { console.log("Audio finished playing"); }); connection.on("error", (err) => { console.error("Voice error:", err); }); } catch (err) { await bot.createMessage(msg.channel.id, `Error: ${err.message}`); } } if (msg.content === "!leave") { const voiceConnection = bot.voiceConnections.get(msg.guildID); if (voiceConnection) { bot.leaveVoiceChannel(voiceConnection.channelID); await bot.createMessage(msg.channel.id, "Left voice channel!"); } } if (msg.content === "!stop") { const voiceConnection = bot.voiceConnections.get(msg.guildID); if (voiceConnection?.playing) { voiceConnection.stopPlaying(); } } }); bot.on("error", (err) => console.error(err)); bot.connect(); ``` -------------------------------- ### Create and Handle Discord Slash Commands with Eris (JavaScript) Source: https://context7.com/abalabahaha/eris/llms.txt This snippet demonstrates how to create global and guild-specific slash commands, user context menus, and handle interactions using the Eris library in JavaScript. It requires the 'eris' package and handles command creation and response logic. ```javascript const Eris = require("eris"); const Constants = Eris.Constants; const bot = new Eris("Bot TOKEN", { intents: [] // No gateway intents needed for interactions }); bot.on("ready", async () => { console.log("Ready!"); // Create a global slash command await bot.createCommand({ name: "greet", description: "Send a greeting", type: Constants.ApplicationCommandTypes.CHAT_INPUT, options: [ { name: "user", description: "User to greet", type: Constants.ApplicationCommandOptionTypes.USER, required: true }, { name: "message", description: "Custom greeting message", type: Constants.ApplicationCommandOptionTypes.STRING, required: false, choices: [ { name: "Hello!", value: "hello" }, { name: "Hi there!", value: "hi" }, { name: "Greetings!", value: "greetings" } ] } ] }); // Create a user context menu command await bot.createCommand({ name: "Get User Info", type: Constants.ApplicationCommandTypes.USER }); // Create a guild-specific command await bot.createGuildCommand("GUILD_ID", { name: "server-info", description: "Get server information", type: Constants.ApplicationCommandTypes.CHAT_INPUT }); }); bot.on("interactionCreate", async (interaction) => { if (interaction instanceof Eris.CommandInteraction) { const { name, options } = interaction.data; if (name === "greet") { const userOption = options.find(o => o.name === "user"); const messageOption = options.find(o => o.name === "message"); const greeting = messageOption?.value || "Hello"; await interaction.createMessage({ content: `${greeting}, <@${userOption.value}>!`, flags: 64 // Ephemeral - only visible to the user }); } } }); bot.on("error", (err) => console.error(err)); bot.connect(); ``` -------------------------------- ### Create and Connect Eris Bot Client Source: https://context7.com/abalabahaha/eris/llms.txt Initializes and connects an Eris bot client to Discord. It requires a bot token and specifies gateway intents, allowed mentions, auto-reconnect, compression settings, and shard count. The snippet also includes basic event listeners for 'ready' and 'error'. ```javascript const Eris = require("eris"); // Create a new client with your bot token // Bot tokens should be prefixed with "Bot " const bot = new Eris("Bot YOUR_BOT_TOKEN", { intents: ["guilds", "guildMessages", "messageContent"], // Specify gateway intents allowedMentions: { everyone: false, // Disable @everyone mentions by default roles: true, users: true }, autoreconnect: true, compress: false, maxShards: "auto" // Let Discord determine optimal shard count }); // Listen for the ready event bot.on("ready", () => { console.log(`Logged in as ${bot.user.username}#${bot.user.discriminator}`); console.log(`Serving ${bot.guilds.size} guilds`); }); // Handle errors bot.on("error", (err) => { console.error("Bot error:", err); }); // Connect to Discord bot.connect(); ``` -------------------------------- ### Manage Guild Members and Roles with Eris Source: https://context7.com/abalabahaha/eris/llms.txt Demonstrates how to perform administrative actions on guild members such as banning, kicking, role assignment, and editing member properties. Requires appropriate intents like 'guildMembers'. ```javascript const Eris = require("eris"); const bot = new Eris("Bot TOKEN", { intents: ["guilds", "guildMembers", "guildMessages", "messageContent"] }); async function banMember(guildID, userID, reason, deleteMessageSeconds = 0) { await bot.banGuildMember(guildID, userID, { deleteMessageSeconds: deleteMessageSeconds, reason: reason }); } async function kickMember(guildID, userID, reason) { await bot.kickGuildMember(guildID, userID, reason); } async function addRole(guildID, memberID, roleID, reason) { await bot.addGuildMemberRole(guildID, memberID, roleID, reason); } async function removeRole(guildID, memberID, roleID, reason) { await bot.removeGuildMemberRole(guildID, memberID, roleID, reason); } async function createRole(guildID) { const role = await bot.createRole(guildID, { name: "New Role", color: 0xFF0000, hoist: true, mentionable: true, permissions: Eris.Constants.Permissions.sendMessages | Eris.Constants.Permissions.readMessages }, "Created by bot"); return role; } async function editMember(guildID, memberID) { await bot.editGuildMember(guildID, memberID, { nick: "New Nickname", mute: false, deaf: false, roles: ["role_id_1", "role_id_2"], communicationDisabledUntil: new Date(Date.now() + 60000) }, "Edited by bot"); } async function getAuditLog(guildID) { const auditLog = await bot.getGuildAuditLog(guildID, { limit: 50, actionType: Eris.Constants.AuditLogActions.MEMBER_BAN_ADD }); return auditLog.entries; } ``` -------------------------------- ### Manage Auto Moderation Rules with Eris Source: https://context7.com/abalabahaha/eris/llms.txt Demonstrates how to create, retrieve, update, and delete auto-moderation rules. It also shows how to listen for execution events triggered by these rules. ```javascript const Eris = require("eris"); const Constants = Eris.Constants; const bot = new Eris("Bot TOKEN", { intents: ["guilds", "autoModerationConfiguration", "autoModerationExecution"] }); async function createKeywordRule(guildID) { const rule = await bot.createAutoModerationRule(guildID, { name: "Block Bad Words", eventType: Constants.AutoModerationEventTypes.MESSAGE_SEND, triggerType: Constants.AutoModerationTriggerTypes.KEYWORD, triggerMetadata: { keyword_filter: ["badword1", "badword2"], regex_patterns: ["b[a@]d.*w[o0]rd"] }, actions: [ { type: Constants.AutoModerationActionTypes.BLOCK_MESSAGE, metadata: { custom_message: "Your message was blocked." } }, { type: Constants.AutoModerationActionTypes.SEND_ALERT_MESSAGE, metadata: { channel_id: "ALERT_CHANNEL_ID" } }, { type: Constants.AutoModerationActionTypes.TIMEOUT, metadata: { duration_seconds: 60 } } ], enabled: true, exemptRoles: ["MODERATOR_ROLE_ID"], exemptChannels: ["BOT_COMMANDS_CHANNEL_ID"] }); return rule; } async function createSpamRule(guildID) { return await bot.createAutoModerationRule(guildID, { name: "Anti-Spam", eventType: Constants.AutoModerationEventTypes.MESSAGE_SEND, triggerType: Constants.AutoModerationTriggerTypes.SPAM, actions: [{ type: Constants.AutoModerationActionTypes.BLOCK_MESSAGE }], enabled: true }); } async function getRules(guildID) { return await bot.getAutoModerationRules(guildID); } async function editRule(guildID, ruleID) { await bot.editAutoModerationRule(guildID, ruleID, { enabled: false }); } async function deleteRule(guildID, ruleID) { await bot.deleteAutoModerationRule(guildID, ruleID); } bot.on("autoModerationActionExecution", (guild, action) => { console.log(`Auto mod triggered: ${action.ruleTriggerType}`); }); bot.connect(); ``` -------------------------------- ### Configure Bot Sharding in Eris Source: https://context7.com/abalabahaha/eris/llms.txt Configures a bot to run across multiple shards, enabling horizontal scaling. Includes manual shard ID assignment and event listeners for shard lifecycle management. ```javascript const Eris = require("eris"); const bot = new Eris("Bot TOKEN", { intents: ["guilds", "guildMembers", "guildPresences"], firstShardID: 0, lastShardID: 3, maxShards: 8, shardConcurrency: "auto", getAllUsers: false }); bot.on("ready", () => console.log(`Ready! ${bot.shards.size} shards running`)); bot.on("shardReady", (shardID) => console.log(`Shard ${shardID} ready!`)); bot.on("shardDisconnect", (err, shardID) => console.log(`Shard ${shardID} disconnected`)); function getGuildShard(guildID) { const shardID = bot.guildShardMap[guildID]; return bot.shards.get(shardID); } bot.connect(); ``` -------------------------------- ### Update Bot Status and Presence with Eris Source: https://context7.com/abalabahaha/eris/llms.txt Shows how to set the bot's online status (online, idle, dnd, invisible) and activity type (playing, streaming, listening, watching, competing, custom) using the Eris library. Requires 'guilds' intent. ```javascript const Eris = require("eris"); const bot = new Eris("Bot TOKEN", { intents: ["guilds"] }); bot.on("ready", () => { console.log("Ready!"); // Set status to playing a game bot.editStatus("online", [{ name: "with Discord.js", type: 0 // 0 = Playing }]); // Set status to streaming bot.editStatus("online", [{ name: "Live Stream", type: 1, // 1 = Streaming url: "https://twitch.tv/username" // Must be a Twitch URL }]); // Set status to listening bot.editStatus("idle", [{ name: "to music", type: 2 // 2 = Listening }]); // Set status to watching bot.editStatus("dnd", [{ name: "over the server", type: 3 // 3 = Watching }]); // Set custom status bot.editStatus("online", [{ name: "Custom Status", type: 4, // 4 = Custom Status state: "This is my custom status" }]); // Set status to competing bot.editStatus("online", [{ name: "in a tournament", type: 5 // 5 = Competing }]); // Set invisible/offline status bot.editStatus("invisible"); // Rotate status const statuses = [ { name: "!help", type: 0 }, { name: `${bot.guilds.size} servers`, type: 3 }, { name: "for commands", type: 2 } ]; let currentStatus = 0; setInterval(() => { bot.editStatus("online", [statuses[currentStatus]]); currentStatus = (currentStatus + 1) % statuses.length; }, 30000); // Rotate every 30 seconds }); bot.on("error", (err) => console.error(err)); bot.connect(); ``` -------------------------------- ### Manage Guild Channels and Permissions with Eris Source: https://context7.com/abalabahaha/eris/llms.txt Provides methods to create, modify, and delete text, voice, and category channels. Also includes logic for updating channel-specific permission overwrites. ```javascript const Eris = require("eris"); const Constants = Eris.Constants; async function createTextChannel(guildID) { return await bot.createChannel(guildID, "new-channel", Constants.ChannelTypes.GUILD_TEXT, { topic: "This is the channel topic", nsfw: false, rateLimitPerUser: 5, parentID: "CATEGORY_ID", permissionOverwrites: [{ id: guildID, type: 0, allow: 0n, deny: BigInt(Constants.Permissions.sendMessages) }], reason: "Created a new channel" }); } async function createVoiceChannel(guildID) { return await bot.createChannel(guildID, "Voice Room", Constants.ChannelTypes.GUILD_VOICE, { bitrate: 64000, userLimit: 10, parentID: "CATEGORY_ID" }); } async function editChannel(channelID) { await bot.editChannel(channelID, { name: "renamed-channel", topic: "Updated topic", rateLimitPerUser: 10, nsfw: true }, "Updated channel settings"); } async function deleteChannel(channelID) { await bot.deleteChannel(channelID, "No longer needed"); } async function editChannelPermissions(channelID, roleID) { await bot.editChannelPermission( channelID, roleID, BigInt(Constants.Permissions.sendMessages | Constants.Permissions.readMessages), BigInt(Constants.Permissions.manageMessages), 0, "Updated permissions" ); } ``` -------------------------------- ### Execute and Manage Webhooks with Eris Source: https://context7.com/abalabahaha/eris/llms.txt Provides methods to create, execute, edit, and delete webhooks. Webhooks enable automated messaging with custom usernames and embedded content. ```javascript async function createWebhook(channelID) { return await bot.createChannelWebhook(channelID, { name: "My Webhook" }, "Created by bot"); } async function executeWebhook(webhookID, webhookToken) { await bot.executeWebhook(webhookID, webhookToken, { content: "Hello from webhook!", wait: true }); } ``` -------------------------------- ### Create Discord Message Components with Eris Source: https://context7.com/abalabahaha/eris/llms.txt This JavaScript code snippet shows how to create messages with interactive buttons (primary, secondary, danger, and link) and select menus (string and user selects) using the Eris library. It handles message creation and interaction responses. ```javascript const Eris = require("eris"); const Constants = Eris.Constants; const bot = new Eris("Bot TOKEN", { intents: ["guilds", "guildMessages", "messageContent"] }); bot.on("messageCreate", async (msg) => { if (msg.content === "!buttons") { await bot.createMessage(msg.channel.id, { content: "Click a button:", components: [ { type: Constants.ComponentTypes.ACTION_ROW, components: [ { type: Constants.ComponentTypes.BUTTON, style: Constants.ButtonStyles.PRIMARY, custom_id: "btn_primary", label: "Primary" }, { type: Constants.ComponentTypes.BUTTON, style: Constants.ButtonStyles.SECONDARY, custom_id: "btn_secondary", label: "Secondary" }, { type: Constants.ComponentTypes.BUTTON, style: Constants.ButtonStyles.DANGER, custom_id: "btn_danger", label: "Danger", emoji: { name: "⚠️" } }, { type: Constants.ComponentTypes.BUTTON, style: Constants.ButtonStyles.LINK, url: "https://discord.com", label: "Visit Discord" } ] } ] }); } if (msg.content === "!select") { await bot.createMessage(msg.channel.id, { content: "Choose an option:", components: [ { type: Constants.ComponentTypes.ACTION_ROW, components: [ { type: Constants.ComponentTypes.STRING_SELECT, custom_id: "color_select", placeholder: "Select a color", min_values: 1, max_values: 1, options: [ { label: "Red", value: "red", emoji: { name: "🔴" } }, { label: "Green", value: "green", emoji: { name: "🟢" } }, { label: "Blue", value: "blue", emoji: { name: "🔵" } } ] } ] }, { type: Constants.ComponentTypes.ACTION_ROW, components: [ { type: Constants.ComponentTypes.USER_SELECT, custom_id: "user_select", placeholder: "Select a user" } ] } ] }); } }); bot.on("interactionCreate", async (interaction) => { if (interaction instanceof Eris.ComponentInteraction) { if (interaction.data.custom_id === "btn_primary") { await interaction.createMessage({ content: "You clicked the primary button!", flags: 64 }); } if (interaction.data.custom_id === "color_select") { const selected = interaction.data.values[0]; await interaction.createMessage({ content: `You selected: ${selected}`, flags: 64 }); } } }); bot.on("error", (err) => console.error(err)); bot.connect(); ``` -------------------------------- ### Handle Message Reactions with Eris Source: https://context7.com/abalabahaha/eris/llms.txt Demonstrates adding, removing, and retrieving users from message reactions. Includes support for both standard Unicode emojis and custom guild emojis. ```javascript async function addReaction(channelID, messageID) { await bot.addMessageReaction(channelID, messageID, "👍"); await bot.addMessageReaction(channelID, messageID, "custom_emoji:123456789"); } async function removeAllReactions(channelID, messageID) { await bot.removeMessageReactions(channelID, messageID); } bot.on("messageReactionAdd", (message, emoji, reactor) => { console.log(`${reactor.id} reacted with ${emoji.name}`); }); ``` -------------------------------- ### Manage Guild Scheduled Events with Eris Source: https://context7.com/abalabahaha/eris/llms.txt Demonstrates how to create, retrieve, edit, and delete scheduled events within a Discord guild using the Eris library. Supports voice and external event types. Requires 'guilds' and 'guildScheduledEvents' intents. ```javascript const Eris = require("eris"); const Constants = Eris.Constants; const bot = new Eris("Bot TOKEN", { intents: ["guilds", "guildScheduledEvents"] }); // Create a voice channel event async function createVoiceEvent(guildID, channelID) { const event = await bot.createGuildScheduledEvent(guildID, { name: "Community Meeting", description: "Weekly community voice chat", scheduledStartTime: new Date(Date.now() + 86400000), // Tomorrow scheduledEndTime: new Date(Date.now() + 90000000), // 1 hour after start privacyLevel: Constants.GuildScheduledEventPrivacyLevel.GUILD_ONLY, entityType: Constants.GuildScheduledEventEntityTypes.VOICE, channelID: channelID }); return event; } // Create an external event async function createExternalEvent(guildID) { const event = await bot.createGuildScheduledEvent(guildID, { name: "Team Meetup", description: "In-person team gathering", scheduledStartTime: new Date(Date.now() + 604800000), // Next week scheduledEndTime: new Date(Date.now() + 615600000), privacyLevel: Constants.GuildScheduledEventPrivacyLevel.GUILD_ONLY, entityType: Constants.GuildScheduledEventEntityTypes.EXTERNAL, entityMetadata: { location: "123 Main Street, City" } }); return event; } // Get guild events async function getEvents(guildID) { const events = await bot.getGuildScheduledEvents(guildID, { withUserCount: true }); return events; } // Get event subscribers async function getEventUsers(guildID, eventID) { const users = await bot.getGuildScheduledEventUsers(guildID, eventID, { limit: 100, withMember: true }); return users; } // Edit an event async function editEvent(guildID, eventID) { await bot.editGuildScheduledEvent(guildID, eventID, { name: "Updated Event Name", status: Constants.GuildScheduledEventStatus.ACTIVE // Start the event }); } // Delete an event async function deleteEvent(guildID, eventID) { await bot.deleteGuildScheduledEvent(guildID, eventID); } bot.on("error", (err) => console.error(err)); bot.connect(); ``` -------------------------------- ### Manage Discord Thread Channels with Eris Source: https://context7.com/abalabahaha/eris/llms.txt Functions to create, join, leave, and retrieve threads within a Discord guild. These methods allow for both message-based and standalone thread initialization. ```javascript async function createThreadFromMessage(channelID, messageID) { return await bot.createThreadWithMessage(channelID, messageID, { name: "Discussion Thread", autoArchiveDuration: 1440, rateLimitPerUser: 5 }); } async function joinThread(threadID) { await bot.joinThread(threadID); } async function getActiveThreads(guildID) { const result = await bot.getActiveGuildThreads(guildID); return result.threads; } ``` -------------------------------- ### POST /channels/{channel.id}/messages Source: https://context7.com/abalabahaha/eris/llms.txt Sends a message to a specific Discord channel using the createMessage method. ```APIDOC ## POST /channels/{channel.id}/messages ### Description Sends a new message to the specified channel. Supports plain text, replies, and rich embeds. ### Method POST ### Endpoint /channels/{channel.id}/messages ### Parameters #### Path Parameters - **channel.id** (string) - Required - The ID of the channel to send the message to. #### Request Body - **content** (string) - Optional - The message contents. - **embeds** (array) - Optional - An array of embed objects. - **messageReference** (object) - Optional - Message reference for replying to a specific message. ### Request Example { "content": "Hello, world!", "messageReference": { "messageID": "123456789012345678" } } ### Response #### Success Response (200) - **id** (string) - The ID of the created message. - **content** (string) - The content of the message. #### Response Example { "id": "987654321098765432", "content": "Hello, world!" } ``` -------------------------------- ### POST /channels/{channel.id}/messages Source: https://context7.com/abalabahaha/eris/llms.txt Sends a message or embed to a previously retrieved direct message channel. ```APIDOC ## POST /channels/{channel.id}/messages ### Description Sends a message to a specific channel, including support for embeds. ### Method POST ### Endpoint /channels/{channel.id}/messages ### Parameters #### Path Parameters - **channel.id** (string) - Required - The ID of the DM channel. #### Request Body - **content** (string) - Optional - The text content of the message. - **embeds** (array) - Optional - An array of embed objects. ### Request Example { "content": "Hello!", "embeds": [{"title": "DM", "description": "Test"}] } ### Response #### Success Response (200) - **id** (string) - The ID of the sent message. #### Response Example { "id": "987654321098765432", "content": "Hello!" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.