Wondering what’s next for npm?Check out our public roadmap! »

This package has been deprecated

Author message:

use @broid/discord instead

broid-discord

1.1.3 • Public • Published

npm node deps tests bithound bithoundscore nsp-checked

Broid Discord Integration

Broid Integrations is an open source project providing a suite of Activity Streams 2 libraries for unified communications among a vast number of communication platforms.

Connect your App to Multiple Messaging Channels with One OpenSource Language.

gitter

Message types supported

Simple Image Video Buttons Location Phone number

Buttons, Location, Phone number are platform limitations.

Getting started

Register your app/bot on Discord

  • Instructions to create bot, can be found here.

Connect to Discord

import broidDiscord from 'broid-discord'
 
const discord = new broidDiscord({ token: "xoxp-xxxxxx" })
 
discord.connect()
  .subscribe({
    next: data => console.log(data),
    error: err => console.error(`Something went wrong: ${err.message}`),
    complete: () => console.log('complete'),
  })

Options availables

name Type default Description
serviceID string random Arbitrary identifier of the running instance
logLevel string info Can be : fatal, error, warn, info, debug, trace
token string Your bot access token

Receive a message

discord.listen()
  .subscribe({
    next: data => console.log(`Received message: ${data}`),
    error: err => console.error(`Something went wrong: ${err.message}`),
    complete: () => console.log('complete'),
  })

Post a message

To send a message, the format should use the broid-schemas.

const message_formated = '...'
 
discord.send(message_formated)
  .then(() => console.log("ok"))
  .catch(err => console.error(err))

Examples of messages

Message received

  • A direct message received from Sally
{
  "@context": "https://www.w3.org/ns/activitystreams",
  "published": 1483491501,
  "type": "Create",
  "generator": {
    "id": "af869e0f-f4e5-424d-a288-1657d843f438",
    "type": "Service",
    "name": "discord"
  },
  "object": {
    "type": "Note",
    "id": "1483491501",
    "content": "hello world on private"
  },
  "target": {
    "type": "Person",
    "id": "152483118161461248"
  },
  "actor": {
    "id": "152486124831181614",
    "type": "Person",
    "name": "sally"
  }
}
  • A message received from Sally on Channel/Group
{
  "@context": "https://www.w3.org/ns/activitystreams",
  "published": 1483491501,
  "type": "Create",
  "generator": {
    "id": "af869e0f-f4e5-424d-a288-1657d843f438",
    "type": "Service",
    "name": "discord"
  },
  "object": {
    "type": "Note",
    "id": "1483491501",
    "content": "hello world on private"
  },
  "target": {
    "type": "Group",
    "id": "152483118161461248",
    "name": "channelname"
  },
  "actor": {
    "id": "152486124831181614",
    "type": "Person",
    "name": "sally"
  }
}

Send a message

  • Send a simple message
{
  "@context": "https://www.w3.org/ns/activitystreams",
  "type": "Create",
  "generator": {
    "id": "f6e92eb6-f69e-4eae-8158-06613461cf3a",
    "type": "Service",
    "name": "discord"
  },
  "object": {
    "type": "Note",
    "content": "hello world"
  },
  "to": {
    "type": "Person",
    "id": "152486124831181614"
  }
}
  • Edit a message
{
  "@context": "https://www.w3.org/ns/activitystreams",
  "type": "Update",
  "generator": {
    "id": "f6e92eb6-f69e-4eae-8158-06613461cf3a",
    "type": "Service",
    "name": "discord"
  },
  "object": {
    "type": "Note",
    "content": "hello world edited",
    "id": "1483406119",
  },
  "to": {
    "type": "Person",
    "id": "152486124831181614"
  }
}
  • Delete a message
{
  "@context": "https://www.w3.org/ns/activitystreams",
  "type": "Delete",
  "generator": {
    "id": "f6e92eb6-f69e-4eae-8158-06613461cf3a",
    "type": "Service",
    "name": "discord"
  },
  "object": {
    "type": "Note",
    "content": "",
    "id": "1483406119",
  },
  "to": {
    "type": "Person",
    "id": "152486124831181614"
  }
}
  • Send a image or a video
{
  "@context": "https://www.w3.org/ns/activitystreams",
  "type": "Create",
  "generator": {
    "id": "f6e92eb6-f69e-4eae-8158-06613461cf3a",
    "type": "Service",
    "name": "discord"
  },
  "object": {
    "content": "image.jpg",
    "type": "Image",
    "url": "https://www.broid.ai/url_of_image.jpg",
  },
  "to": {
    "type": "Person",
    "id": "152486124831181614"
  }
}

Contributing to Broid

Broid is an open source project. Broid wouldn't be where it is now without contributions by the community. Please consider forking Broid to improve, enhance or fix issues. If you feel like the community will benefit from your fork, please open a pull request.

And because we want to do the better for you. Help us improving Broid by sharing your feedback on our Integrations GitHub Repo and let's build Broid together!

Code of Conduct

Make sure that you're read and understand the Code of Conduct.

Copyright & License

Copyright (c) 2016-2017 Broid.ai

This project is licensed under the AGPL 3, which can be found here.

Keywords

none

Install

npm i broid-discord

DownloadsWeekly Downloads

6

Version

1.1.3

License

AGPL-3.0+

Last publish

Collaborators

  • avatar