Discord Message avatar
Discord Message

Pricing

Pay per usage

Go to Store
Discord Message

Discord Message

Developed by

Christian LeMoussel

Christian LeMoussel

Maintained by Community

This actor sends a message to Discord automatically. It can be used separately, or as a notification tool at the end of other actors.

0.0 (0)

Pricing

Pay per usage

2

Total users

37

Monthly users

1

Runs succeeded

>99%

Last modified

2 years ago

.dockerignore

# configurations
.idea
.vscode
.dccache
package-lock.json
# crawlee and apify storage folders
apify_storage
crawlee_storage
storage
# installed files
node_modules
# git folder
.git

.gitignore

node_modules
.vscode
.dccache
package-lock.json
apify_storage
crawlee_storage
storage

package.json

{
"name": "discord-message",
"version": "0.0.1",
"type": "module",
"description": "This is an example of an Apify actor.",
"dependencies": {
"apify": "^3.0.0",
"discord.js": "^14.7.1"
},
"scripts": {
"start": "node src/main.js",
"test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
},
"author": "It's not you it's me",
"license": "ISC"
}

.actor/actor.json

{
"actorSpecification": 1,
"name": "discord-message",
"title": "Discord Message",
"description": "This actor send message to Discord automatically.",
"version": "1.0",
"buildTag": "latest",
"input": "./input-schema.json",
"readme": "./README.md",
"dockefile": "./Dockerfile"
}

.actor/Dockerfile

# Specify the base Docker image. You can read more about
# the available images at https://sdk.apify.com/docs/guides/docker-images
# You can also use any other image from Docker Hub.
FROM apify/actor-node:16
# Copy just package.json and package-lock.json
# to speed up the build using Docker layer cache.
COPY package*.json ./
# Install NPM packages, skip optional and development dependencies to
# keep the image small. Avoid logging too much and print the dependency
# tree for debugging
RUN npm --quiet set progress=false \
&& npm install --omit=dev --omit=optional \
&& echo "Installed NPM packages:" \
&& (npm list --omit=dev --all || true) \
&& echo "Node.js version:" \
&& node --version \
&& echo "NPM version:" \
&& npm --version \
&& rm -r ~/.npm
# Next, copy the remaining files and directories with the source code.
# Since we do this after NPM install, quick build will be really fast
# for most source file changes.
COPY . ./
# Run the image.
CMD npm start --silent

.actor/input-schema.json

{
"title": "Send message to a Discord Webhook",
"type": "object",
"schemaVersion": 1,
"properties": {
"webhookUrl": {
"title": "Url",
"type": "string",
"description": "Discord Webhook Url in a format https://discord.com/api/webhooks/",
"isSecret": true,
"editor": "textfield"
},
"text": {
"title": "Message",
"type": "string",
"description": "Message that will be sent to Discord",
"prefill": "Hello from 'Discord-Message' Apify actor!",
"example": "Hello from 'Discord-Message' Apify actor!",
"editor": "textfield"
}
},
"required": ["webhookUrl", "text"]
}

.actor/README.md

1# Discord message
2
3This actor sends message to [Discord](https://discord.com/) automatically. It can be used separately, or as a notificaton tool at the end of other actors.
4
5## Discord Webhook setup
6
7It is necessary to create a webhooks through the Discord server settings.You can create webhooks directly through the Discord client. Go to Server Settings, and you will see an `Integrations` tab.
8
9![Create discord webhook](https://discordjs.guide/assets/creating-webhooks-1.9d51faa6.png)
10
11If you already have created a webhook, the webhooks tab will look like this; you will need to click the `View Webhooks` button.
12
13![View discord webhook](https://discordjs.guide/assets/creating-webhooks-2.24d92370.png)
14
15Once you are there, click on the `Create Webhook / New Webhook` button; this will create a webhook. From here, you can edit the channel, the name, and the avatar. Copy the link, the first part is the id, and the second is the token.
16
17![View discord webhook](https://discordjs.guide/assets/creating-webhooks-3.1fddb27b.png)
18
19Copy your webhook URL and save it for later.
20
21Ref: [Discord webhook](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks)
22
23## Input
24
25The following table shows specification of the actor INPUT fields as defined by its input schema.
26
27Field | Type | Description
28---| ---| ---|
29Url| *String*| (required) Discord Webhook URL
30Message| *String*| (required) Message that will be sent to Discord (i.e. "Hello from 'Discord-Message' Apify actor!" ).
31
32## How to run
33
34To run the actor, you'll need an [Apify account](https://my.apify.com/). Simply create a new task for the actor by clicking the green button above, modify the actor input configuration, click Run and get your results.
35
36## API
37
38To run the actor from your code, send a HTTP POST request to the following API endpoint: **TODO**
39
40## CU usage
41
42Approximately 0.001 CU per run.
43
44## Documentation reference
45
46- [Apify Actor documentation](https://docs.apify.com/actor)
47- [Apify CLI](https://docs.apify.com/cli)

src/main.js

1// https://sdk.apify.com/
2import { Actor, log } from 'apify';
3// https://discord.js.org/
4import { WebhookClient } from 'discord.js'
5
6(async () => {
7 await Actor.init()
8
9 const input = await Actor.getInput();
10
11 const webhookClient = new WebhookClient({'url': input.webhookUrl});
12 // https://discord.com/developers/docs/resources/webhook#execute-webhook
13 await webhookClient
14 .send({'content': input.text})
15 .then((result) => {
16 const resultDateFormat = result.timestamp.
17 replace(/T/, ' '). // replace T with a space
18 replace(/\..+/, '') // delete the dot and everything after
19 log.info(`${resultDateFormat} Discord message sent successfully`);
20 })
21 .catch((error) => {
22 log.error(`Failed to send Slack message: ${error.code}`);
23 throw error;
24 });
25
26 await Actor.exit();
27})();