Discord webhooks now mirror character log

This commit is contained in:
Stefan Zermatten
2020-10-13 12:42:02 +02:00
parent a104fc8a87
commit 0af0afc0d0

View File

@@ -1,24 +1,23 @@
import Discord from 'discord.js' import Discord from 'discord.js'
export default function sendWebhook({webhookURL, message}){ export default function sendWebhook({webhookURL, message, options}){
//webhookURL = https://discordapp.com/api/webhooks/<id>/<token> //webhookURL = https://discordapp.com/api/webhooks/<id>/<token>
let urlArray = webhookURL.split('/'); let urlArray = webhookURL.split('/');
let token = urlArray.pop(); let token = urlArray.pop();
let id = urlArray.pop(); let id = urlArray.pop();
// const hook = new Discord.WebhookClient(webhook.id, webhook.token);
const hook = new Discord.WebhookClient(id, token); const hook = new Discord.WebhookClient(id, token);
// Send a message using the webhook // Send a message using the webhook
hook.send(message); hook.send(message, options)
} }
export function sendWebhookAsCreature({creature, content, embeds}){ export function sendWebhookAsCreature({creature, content, embeds}){
if (!creature || !creature.discordWebhook) return; if (!creature || !creature.settings || !creature.settings.discordWebhook) return;
sendWebhook({ sendWebhook({
webhookURL: creature.discordWebhook, webhookURL: creature.settings.discordWebhook,
message: { message: content,
options: {
username: creature.name, username: creature.name,
avatar_url: creature.avatarPicture, avatarURL: creature.avatarPicture,
content,
embeds, embeds,
} },
}); });
} }