|
| 1 | +--- |
| 2 | +layout: page |
| 3 | +title: "Discord" |
| 4 | +description: "Instructions how to add Discord notifications to Home Assistant." |
| 5 | +date: 2016-01-14 15:15 |
| 6 | +sidebar: true |
| 7 | +comments: false |
| 8 | +sharing: true |
| 9 | +footer: true |
| 10 | +logo: discord.png |
| 11 | +ha_category: Notifications |
| 12 | +--- |
| 13 | + |
| 14 | +The [Discord service](https://discordapp.com/) is a platform for the notify component. This allows components to send messages to the user using Discord. |
| 15 | + |
| 16 | +In order to get a token you need to go to the [Discord My Apps page](https://discordapp.com/developers/applications/me) and create a new application. Once the application is ready, create a bot user. Retreive the client ID and the (hidden) token of your bot for later. |
| 17 | + |
| 18 | +When setting up the application you can use this [icon](https://home-assistant.io/demo/favicon-192x192.png). |
| 19 | + |
| 20 | +### {% linkable_title Configuration %} |
| 21 | + |
| 22 | +To use Discord notifications, add the following to your `configuration.yaml` file: |
| 23 | + |
| 24 | +```yaml |
| 25 | +# Example configuration.yaml entry |
| 26 | +notify: |
| 27 | + - name: NOTIFIER_NAME |
| 28 | + platform: discord |
| 29 | + token: A1aB2b.C3cD4d-E5eF6f |
| 30 | +``` |
| 31 | +
|
| 32 | +Configuration variables: |
| 33 | +
|
| 34 | +- **name** (*Optional*): Setting the optional parameter `name` allows multiple notifiers to be created. The default value is `notify`. The notifier will bind to the service `notify.NOTIFIER_NAME`. |
| 35 | +- **token** (*Required*): Your bot's token. |
| 36 | + |
| 37 | +### {% linkable_title Using the bot %} |
| 38 | +Bots can only send messages to servers. To add the bot to a server you are an admin on, use the Discord OAuth2 Authorization page: |
| 39 | + |
| 40 | +[https://discordapp.com/api/oauth2/authorize?client_id=1234567890&scope=bot&permissions=0](https://discordapp.com/api/oauth2/authorize?client_id=1234567890&scope=bot&permissions=0) |
| 41 | + |
| 42 | +Replace the client ID with the appropriate one from the [Discord My Apps page](https://discordapp.com/developers/applications/me). |
| 43 | + |
| 44 | +Once the bot user has been added to your server, get the channel ID of the channel you want the bot to operate in. |
| 45 | +* In The Discord app go to Settings > Appearance > Check developer mode |
| 46 | +* Right click channel name > Copy ID |
| 47 | + |
| 48 | +This channel ID has to be used as the target when calling the notification service. Multiple channel IDs can be specified, across multiple servers. |
| 49 | + |
| 50 | +#### {% linkable_title Example service payload %} |
| 51 | + |
| 52 | +```json |
| 53 | +{ |
| 54 | + "message": "A message from Home Assistant", |
| 55 | + "target": [ |
| 56 | + "1234567890", |
| 57 | + "0987654321" |
| 58 | + ] |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +### {% linkable_title Notes %} |
| 63 | + |
| 64 | +For more information about creating and authorizing bots, visit the [OAuth2 information page](https://discordapp.com/developers/docs/topics/oauth2) |
| 65 | + |
| 66 | +To use notifications effectively, please see the [getting started with automation page](/getting-started/automation/). |
0 commit comments