import requests
import json


def Discord(keys, message, delete=False):
    """
    Sends a message to Discord and returns response.
    Response contains an 'id' of the sent message.
    """

    url = (
        'https://discordapp.com/api/channels/{channelID}/messages'
        ).format(**keys)

    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': ''
    }

    headers['Authorization'] = 'Bot {authKey}'.format(**keys)

    if not delete:
        payload = {
            "content": message
        }

        response = requests.post(
            url, data=json.dumps(payload), headers=headers
            )

        return response

    else:
        url_del = url + '/{id}'.format(id=message)
        response = requests.delete(url_del, headers=headers)

        return response