community.general.discord (8.5.0) — module

Send Discord messages

| "added in version" 3.1.0 of community.general"

Authors: Christian Wollinger (@cwollinger)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

Sends a message to a Discord channel using the Discord webhook API.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Send a message to the Discord channel
  community.general.discord:
    webhook_id: "00000"
    webhook_token: "XXXYYY"
    content: "This is a message from ansible"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Send a message to the Discord channel with specific username and avatar
  community.general.discord:
    webhook_id: "00000"
    webhook_token: "XXXYYY"
    content: "This is a message from ansible"
    username: Ansible
    avatar_url: "https://docs.ansible.com/ansible/latest/_static/images/logo_invert.png"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Send a embedded message to the Discord channel
  community.general.discord:
    webhook_id: "00000"
    webhook_token: "XXXYYY"
    embeds:
      - title: "Embedded message"
        description: "This is an embedded message"
        footer:
          text: "Author: Ansible"
        image:
          url: "https://docs.ansible.com/ansible/latest/_static/images/logo_invert.png"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Send two embedded messages
  community.general.discord:
    webhook_id: "00000"
    webhook_token: "XXXYYY"
    embeds:
      - title: "First message"
        description: "This is my first embedded message"
        footer:
          text: "Author: Ansible"
        image:
          url: "https://docs.ansible.com/ansible/latest/_static/images/logo_invert.png"
      - title: "Second message"
        description: "This is my first second message"
        footer:
          text: "Author: Ansible"
          icon_url: "https://docs.ansible.com/ansible/latest/_static/images/logo_invert.png"
        fields:
          - name: "Field 1"
            value: "Value of my first field"
          - name: "Field 2"
            value: "Value of my second field"
        timestamp: "{{ ansible_date_time.iso8601 }}"

Inputs

    
tts:
    default: false
    description:
    - Set this to V(true) if this is a TTS (Text to Speech) message.
    type: bool

embeds:
    description:
    - Send messages as Embeds to the Discord channel.
    - Embeds can have a colored border, embedded images, text fields and more.
    - 'Allowed parameters are described in the Discord Docs: U(https://discord.com/developers/docs/resources/channel#embed-object)'
    - At least one of O(content) and O(embeds) must be specified.
    elements: dict
    type: list

content:
    description:
    - Content of the message to the Discord channel.
    - At least one of O(content) and O(embeds) must be specified.
    type: str

username:
    description:
    - Overrides the default username of the webhook.
    type: str

avatar_url:
    description:
    - Overrides the default avatar of the webhook.
    type: str

webhook_id:
    description:
    - The webhook ID.
    - 'Format from Discord webhook URL: C(/webhooks/{webhook.id}/{webhook.token}).'
    required: true
    type: str

webhook_token:
    description:
    - The webhook token.
    - 'Format from Discord webhook URL: C(/webhooks/{webhook.id}/{webhook.token}).'
    required: true
    type: str

Outputs

http_code:
  description:
  - Response Code returned by Discord API.
  returned: always
  sample: 204
  type: int

See also