Join Discord

Enter your email to get updates
What is Membrane?
Membrane is a hosted TypeScript runtime specifically designed to build personal automation tools and interact with APIs more easily.
FEATURES
EXAMPLES
example-discord-bot
Create a Discord command that responds with the weather. Use the command/weather 'city-name' in discord.
Reference to a Discord Guild
Subscribe to Discord's slash command.
Get weather information for a city
Respond slash command with weather details
import { nodes, root, state } from "membrane";

export async function configure({ guildId }) {
  const gref = nodes.discord.guilds.one({ id: guildId });

  await gref.createCommand({
    name: "weather",
    description: "Get the weather for a location",
    options: [
      {
        type: 3,
        description: "The city to get the weather for",
        name: "city",
      },
    ],
  });

  await gref.onSlashCommand.$subscribe(root.handleEvent);   
}
        
export async function handleEvent(_, { event }) {
  const { token, application_id, options } = await event;

  const [data] = JSON.parse(options);
  const city = data.value;

  const weather = await nodes.weather
    .now({ city })
    .$query(`{ temp feels_like }`);

  await nodes.discord.followUpWebhook({
    token,
    application_id,
    message: {
      content: `The weather in ${city.toUpperCase()} 
      is ${weather.temp} degrees, 
      but feels like ${weather.feels_like}.`,
    },
  });
}
Install From VS Code
Dev Blog