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