Zum Hauptinhalt springen

Discord Smart-Home-Integration, kostenlos und Open Source

Discord-Integration für Gladys Assistant

Unofficial connector: chat with Gladys and get its notifications through your Discord bot.

Info

Die Dokumentation dieser Integration wird von ihrem Autor geschrieben und ist bisher nur auf Englisch verfügbar.

Unofficial connector, not affiliated with Discord. It turns a Discord bot that you create into a Gladys messaging channel, like the Telegram one: you talk to Gladys in a direct message with your bot, and Gladys answers and notifies you there. Discord is a trademark of Discord Inc.

What you get​

SurfaceContent
Chat with Gladysevery direct message you send the bot goes to Gladys, the answer comes back in the same conversation
Notificationsthe messages Gladys sends you (the "Send a message" scene action, camera images, system messages) arrive as Discord direct messages
Scene triggerDiscord command received: a direct message starting with !, like !garage open, starts your scenes instead of going to the assistant
Scene actionPost in a Discord channel: a text in a channel of a server (a family server, a home log channel…)
Configurationthe Test the bot button checks the token, the connection and the default channel, and gives the invite link of the bot

Setup​

Create the bot​

  1. Open the Discord Developer Portal and click New Application. Give it a name, for instance "Gladys".
  2. Open the Bot page and click Reset Token, then copy the token. It is the password of your bot: never share it. You can also turn off Public Bot, so that only you can invite it.
  3. Leave the three Privileged Gateway Intents off: the integration only reads direct messages, and Discord delivers their text to a bot without any privileged intent (the "Message Content" intent is only needed for messages in servers).

Connect it to Gladys​

  1. In Gladys, paste the token in Bot token and save. The status shows "Connected as …" after a few seconds.
  2. Click Test the bot: the result ends with the invite link of your bot.

Invite it to a server you are in​

Discord only lets a bot and a person exchange direct messages when they share a server.

  1. Open the invite link and pick a server you are a member of. No server of your own? In Discord, click + then Create My Own: a private server with just you (and your family) is perfect. The link is the one the OAuth2 → URL Generator page of the portal would build with the scope bot and the permissions View Channels, Send Messages and Attach Files.
  2. Check that the members of that server may send you direct messages: server name → Privacy Settings → Direct Messages on.
  1. In Gladys, on the page of the integration, click Generate a link code in the Link my account block: a code of 8 characters appears (it works once, for 15 minutes).
  2. In Discord, open a direct message with the bot (click its name in the member list of the server, then Message) and send the code. The bot answers "Linked! Hello …".

Every Gladys user who wants Discord does the same with their own Discord account. A user can unlink from the same block at any time.

Talking to Gladys​

  • Every direct message from a linked account goes to Gladys, with the authority of the linked Gladys user, exactly like the Gladys chat. Like the Gladys chat, the assistant needs Gladys Plus: without it, Gladys answers that Gladys Plus is required (the ! commands below work without it).
  • Answers and notifications arrive in the same conversation. A text longer than the 2,000 characters of a Discord message is split, and a camera image arrives as an image.
  • An account that is not linked gets the linking instructions, nothing else.

Scene commands with !​

A direct message starting with ! is not sent to the assistant: it fires the scene trigger Discord command received, and the bot confirms "Command "garage" passed to your scenes". Only linked accounts can do it.

  • The Command filter is the word right after the !. Gladys compares it exactly, so type it in lowercase and without accents: the integration lowers the case and drops the accents of what you send, so !Garage, !garage and !GARAGE all match the filter garage. Leave the filter empty to react to every command.
  • The scene can use the details of the message: the command, the text after it (!garage open gives open), the whole message, the Gladys user (first name and selector) and the Discord user (id and name).

For instance: trigger Discord command received with the command garage, then the action that opens the garage door; you open it by sending !garage to the bot.

Posting in a server channel​

The scene action Post in a Discord channel posts a text in a channel of a server the bot belongs to. Give it the channel id, or fill Default server channel id in the configuration and leave the field empty. To copy an id, turn on Developer Mode (Discord settings → Advanced), then right-click the channel → Copy Channel ID. The bot needs the View Channel and Send Messages permissions in that channel. The action gives back the id of the posted message.

Options​

  • Allowed Discord user ids: a safety list. When filled, the bot ignores the direct messages of everyone else, link codes included, without answering. Right-click a user → Copy User ID (Developer Mode).
  • Default server channel id: the channel of the Post in a Discord channel action when the action names none.

Troubleshooting​

  • "Discord refused the bot token": the token was reset or mistyped. Click Reset Token in the portal, paste the new one and save.
  • The bot does not answer: check the status of the integration, the allowed list, and that the bot is in a server you share. A message from an account that is not linked gets the linking instructions.
  • "Discord refuses to deliver a direct message": the person does not share a server with the bot anymore, or blocks direct messages from that server's members.
  • "This code is invalid or expired": a code works once, for 15 minutes; generate a new one.
  • A short connection loss to Discord is normal: the integration resumes the session by itself, and only reports it after 30 seconds.
  • Logs: the log level of the integration is set with the LOG_LEVEL variable.

Privacy​

The bot token is stored encrypted by Gladys and is only ever sent to Discord. Your messages travel through Discord like any Discord message. The integration writes nothing on disk: Gladys only keeps the link between a Discord user id and a Gladys user, which you can remove from the Link my account block.

Konfigurationseinstellungen​

Diese Einstellungen fragt Discord in seinem Konfigurationsbildschirm in Gladys ab.

EinstellungTypPflichtfeldBeschreibung
Discord in GladyssectionNeinUnofficial connector, not affiliated with Discord. A Discord bot you create becomes a Gladys chat channel: each Gladys user links their Discord account once, then talks to Gladys in direct messages with the bot and receives its answers and notifications there. Create the bot on the Discord Developer Portal (New Application, then Bot, then Reset Token), paste its token below, save, and use the invite link given by the "Test the bot" button to add it to a server you are a member of.
Bot tokensecretJaDeveloper Portal → your application → Bot → Reset Token. Stored encrypted by Gladys; never share it.
Link your Discord accountsectionNeinEach Gladys user clicks "Generate a link code" in the "Link my account" block and sends the 8-character code to the bot in a Discord direct message (a code works once, for 15 minutes). After that, the messages you send the bot go to Gladys, and Gladys answers there. A message starting with ! (like "!garage open") is not sent to the assistant: it fires the "Discord command received" scene trigger instead.
Allowed Discord user ids (optional)stringNeinSafety list: when filled, the bot ignores the direct messages of everyone else, link codes included. Ids separated by commas (Discord: Settings → Advanced → Developer Mode, then right-click a user → Copy User ID).
Default server channel id (optional)stringNeinChannel used by the "Post in a Discord channel" scene action when it names none (right-click the channel → Copy Channel ID). The bot must be a member of that server.

So installierst du Discord in Gladys​

  1. Öffne in Gladys Integrationen: Discord erscheint im Katalog neben den nativen Integrationen, mit einem Community-Badge.
  2. Klicke auf Installieren. Gladys lädt das Docker-Image (ghcr.io/lm1lc3n7/gladys-discord:0.1.1) herunter, startet es in einer vom Kern isolierten Sandbox und erzeugt die Oberfläche der Integration (Geräte, Erkennung und Konfiguration).
  3. Öffne den Bildschirm Konfiguration der Integration, fülle die Einstellungen aus und speichere.
  4. Du kannst sie auch direkt über die URL ihres Repositorys installieren: https://github.com/LM1LC3N7/gladys-discord.

Discord benötigt Gladys >=5.1.0. Der Katalog in Gladys wird stündlich aktualisiert, eine neue Version ist also spätestens eine Stunde nach ihrer Veröffentlichung verfügbar.

Du nutzt Gladys noch nicht? Es ist kostenlos und Open Source: folge der Installationsanleitung, um loszulegen.

Über externe Integrationen​

Discord ist eine externe Integration: eine Community-Integration, die als Docker-Container verpackt und auf GitHub veröffentlicht wird. Gladys installiert sie mit einem Klick und führt sie in einer vom Kern isolierten Sandbox aus. Sie wird von LM1LC3N7 veröffentlicht und gepflegt, nicht vom Gladys-Kernteam.

Abonniere den Newsletter von Gladys Assistant

Ein paar E-Mails im Monat zu neuen Releases und Neuigkeiten aus dem Projekt. Verschickt von Pierre-Gilles Leymarie, dem Gründer des Projekts. Jederzeit abbestellbar 🙂