Discord

This is the Discord integration for sending Messages from XSOAR to Discord server made by Trustnet

Utilities · Discord

Details

IDDiscord
ProviderTencent
CategoryUtilities
From Version6.0.0
Docker Imagedemisto/python3:3.12.8.3296088
Supported ModulesAgentix XSIAM

README

This is the Discord integration for sending Messages from XSOAR to Discord server made by Trustnet

Configure Discord in Cortex

Parameter Description Required
Api Key You’ll find your api key in BOT section -> Reset Token True
Channel ID You’ll find your channel id by click on your channle then “Copy Channel ID” True

Commands

You can execute these commands from the CLI, as part of an automation, or in a playbook.
After you successfully execute a command, a DBot message appears in the War Room with the command details.

discord-send-message


Send message to your channel

Base Command

discord-send-message

Input

Argument Name Description Required
text Enter your text. Required

Context Output

Path Type Description
Discord.Message.id unknown Message ID
Discord.Message.content unknown Content
Discord.Message.channel_id unknown Channel ID

discord-get-message


Get message details

Base Command

discord-get-message

Input

Argument Name Description Required
message_id Right click on message then “Copy Message ID”. Required

Context Output

Path Type Description
Discord.Details.id unknown Message ID
Discord.Details.content unknown Message Content
Discord.Details.channel_id unknown Message Channel ID
Discord.Details.author.id unknown Message Author ID
Discord.Details.author.username unknown Message Author User Name

Configuration parameters

  • api_key — Api Key
  • credentials
  • channel_id — Channel ID (required)

Commands (2)

  • discord-get-message

    Get message details

  • discord-send-message

    Send message to your channel

import demistomock as demisto  # noqa: F401
from CommonServerPython import *  # noqa: F401
import requests
import json


def send_message(api_key, channel_id, text):
    url = f"https://discord.com/api/v9/channels/{channel_id}/messages"
    headers = {"Authorization": "Bot " + api_key, "Content-Type": "application/json"}
    payload = {
        "content": text,
    }
    response = requests.post(url, headers=headers, data=json.dumps(payload))
    if not response.ok:
        raise DemistoException(
            f"Error in API call to Discord: {response.status_code} - {response.reason}.\nFull response: {response.text}"
        )
    message_id = response.json()["id"]
    content = response.json()["content"]
    channel_id = response.json()["channel_id"]
    alerts = {"id": message_id, "content": content, "channel_id": channel_id}

    command_results = CommandResults(outputs_prefix="Discord.Message", outputs_key_field="id", outputs=alerts)
    return_results(command_results)


def get_message(api_key, channel_id, message_id):
    url = f"https://discord.com/api/v9/channels/{channel_id}/messages/{message_id}"

    headers = {"Authorization": "Bot " + api_key, "Content-Type": "application/json"}
    response = requests.get(url, headers=headers)
    if not response.ok:
        raise DemistoException(
            f"Error in API call to Discord: {response.status_code} - {response.reason}.\nFull response: {response.text}"
        )
    details = response.json()
    msg_id = details["id"]
    msg = details["content"]
    channel_id = details["channel_id"]
    author_id = details["author"]["id"]
    author_user = details["author"]["username"]
    alert = {"id": msg_id, "content": msg, "channel_id": channel_id, "author": {"id": author_id, "username": author_user}}
    command_results = CommandResults(outputs_prefix="Discord.Details", outputs_key_field="id", outputs=alert)
    return_results(command_results)


def test_module(api_key):
    url = "https://discord.com/api/v9/users/@me"
    headers = {"Authorization": "Bot " + api_key, "Content-Type": "application/json"}
    response = requests.get(url, headers=headers)
    if response.status_code == 200:
        return "ok"
    else:
        return "Please check your API key or connection"


def main():
    params = demisto.params()
    api_key = params.get("credentials", {}).get("password") or params.get("api_key")
    if not api_key:
        return_error("Please provide a valid API key")
    channel_id = params.get("channel_id")
    try:
        if demisto.command() == "discord-send-message":
            text = demisto.args()["text"]
            send_message(api_key, channel_id, text)
        elif demisto.command() == "discord-get-message":
            message_id = demisto.args()["message_id"]
            get_message(api_key, channel_id, message_id)
        elif demisto.command() == "test-module":
            return_results(test_module(api_key))
    except Exception as err:
        return_error(str(err))


if __name__ in ["__builtin__", "builtins", "__main__"]:
    main()