Skip to main content

Post a message to Discord

We will register a bot with Discord, keep its token somewhere safe, and post a message to a channel from a flow.

Create the bot on Discord

This half happens on Discord's side, not Robomotion's.

  1. Sign in at discord.com and open the applications page.

  2. Top right, click New Application.

    New Application

  3. Name it and create it.

    Create Bot

  4. In the left menu click Bot, then Add Bot.

  5. Click Reset Token and copy the token. This is the credential the flow will use — treat it like a password, and keep it somewhere you can paste from in a moment.

  6. In the left menu click OAuth2URL Generator. Under Scopes tick bot, then pick the bot permissions you need. This tutorial only needs Send Messages.

  7. Copy the URL generated at the bottom of the page and open it. Choose the server to add the bot to, click Continue, then Authorize. The bot is now a member of your server.

Store the token in a vault

A bot token grants control of the bot, so it does not belong in a node property where it would be visible to anyone who opens the flow. Robomotion keeps credentials in Vaults, encrypted and referenced by name.

  1. Open Vault from the left rail. Create a vault if you do not already have one — the vault walkthrough covers creating one and the Secret Key it gives you.

    Vault list

    Save the Secret Key

    A vault's Secret Key is shown once, when the vault is created, and cannot be recovered. A vault whose key you did not save can never be opened again.

  2. Open the vault, click New Item, and choose API Key.

    Create Vault Item

  3. Name the item something you will recognise in a dropdown, paste the bot token into the value field, and Save.

    Vault Item

Build the flow

  1. Install the Discord Bot package — see installing packages.

  2. Create a project and build this:

    Flow

    Name on the canvasNode
    StartTrigger → Inject
    ConnectDiscord Bot → Connect
    Send Channel MessageDiscord Bot → Send Message
    DisconnectDiscord Bot → Disconnect
    StopFlow → Stop

    Connect logs the bot in and puts a client id in the message; every node after it uses that id to say which bot session it means. Disconnect closes the session — do it even on a short flow, for the same reason you close a file you opened.

  3. Click Connect and pick your vault item under Bot Token.

    Bot Token

    The dropdown lists vaults and their items. The token itself never appears in the flow — only a reference to it.

  4. Click Send Channel Message and fill in the Channel Id and Message Text.

    To get a channel id, right-click the channel in Discord and choose Copy Channel ID.

    Discord Channel Id

    note

    No Copy Channel ID in the menu? Turn on Developer Mode in Discord under Settings → Advanced.

  5. Run the flow. The message appears in the channel.

    Result

Try changing it

  • Put the message text in a Function node so it can include a date, a count, or anything else the flow worked out.
  • Trigger it from a Schedule for a daily standup post.
  • Swap Send Message for Send Direct Message to reach one person instead of a channel — see the Discord package reference.