Discord Message
Try for free
No credit card required
Go to Store
Discord Message
lemoussel/discord-message
Try for free
No credit card required
This actor sends a message to Discord automatically. It can be used separately, or as a notification tool at the end of other actors.
.dockerignore
1# configurations
2.idea
3.vscode
4.dccache
5package-lock.json
6
7# crawlee and apify storage folders
8apify_storage
9crawlee_storage
10storage
11
12# installed files
13node_modules
14
15# git folder
16.git
.gitignore
1node_modules
2.vscode
3.dccache
4package-lock.json
5apify_storage
6crawlee_storage
7storage
package.json
1{
2 "name": "discord-message",
3 "version": "0.0.1",
4 "type": "module",
5 "description": "This is an example of an Apify actor.",
6 "dependencies": {
7 "apify": "^3.0.0",
8 "discord.js": "^14.7.1"
9 },
10 "scripts": {
11 "start": "node src/main.js",
12 "test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
13 },
14 "author": "It's not you it's me",
15 "license": "ISC"
16}
.actor/actor.json
1{
2 "actorSpecification": 1,
3 "name": "discord-message",
4 "title": "Discord Message",
5 "description": "This actor send message to Discord automatically.",
6 "version": "1.0",
7 "buildTag": "latest",
8 "input": "./input-schema.json",
9 "readme": "./README.md",
10 "dockefile": "./Dockerfile"
11}
.actor/Dockerfile
1# Specify the base Docker image. You can read more about
2# the available images at https://sdk.apify.com/docs/guides/docker-images
3# You can also use any other image from Docker Hub.
4FROM apify/actor-node:16
5
6# Copy just package.json and package-lock.json
7# to speed up the build using Docker layer cache.
8COPY package*.json ./
9
10# Install NPM packages, skip optional and development dependencies to
11# keep the image small. Avoid logging too much and print the dependency
12# tree for debugging
13RUN npm --quiet set progress=false \
14 && npm install --omit=dev --omit=optional \
15 && echo "Installed NPM packages:" \
16 && (npm list --omit=dev --all || true) \
17 && echo "Node.js version:" \
18 && node --version \
19 && echo "NPM version:" \
20 && npm --version \
21 && rm -r ~/.npm
22
23# Next, copy the remaining files and directories with the source code.
24# Since we do this after NPM install, quick build will be really fast
25# for most source file changes.
26COPY . ./
27
28
29# Run the image.
30CMD npm start --silent
.actor/input-schema.json
1{
2 "title": "Send message to a Discord Webhook",
3 "type": "object",
4 "schemaVersion": 1,
5 "properties": {
6 "webhookUrl": {
7 "title": "Url",
8 "type": "string",
9 "description": "Discord Webhook Url in a format https://discord.com/api/webhooks/",
10 "isSecret": true,
11 "editor": "textfield"
12 },
13 "text": {
14 "title": "Message",
15 "type": "string",
16 "description": "Message that will be sent to Discord",
17 "prefill": "Hello from 'Discord-Message' Apify actor!",
18 "example": "Hello from 'Discord-Message' Apify actor!",
19 "editor": "textfield"
20 }
21 },
22 "required": ["webhookUrl", "text"]
23}
.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})();
Developer
Maintained by Community
Actor Metrics
3 monthly users
-
2 stars
0% runs succeeded
Created in Dec 2022
Modified 2 years ago
Categories