out-of-your-element/m2d/actions/send-message.js

24 lines
871 B
JavaScript
Raw Normal View History

2023-06-30 03:15:34 +00:00
// @ts-check
const assert = require("assert").strict
const DiscordTypes = require("discord-api-types/v10")
const passthrough = require("../../passthrough")
const {sync, discord, db} = passthrough
/** @type {import("./register-webhook")} */
const registerWebhook = sync.require("./register-webhook")
/**
* @param {string} channelID
2023-07-02 13:06:05 +00:00
* @param {DiscordTypes.RESTPostAPIWebhookWithTokenJSONBody & {files?: {name: string, file: Buffer}[]}[]} data
2023-06-30 03:15:34 +00:00
*/
// param {DiscordTypes.RESTPostAPIWebhookWithTokenQuery & {wait: true, disableEveryone?: boolean}} options
async function sendMessage(channelID, data) {
const result = await registerWebhook.withWebhook(channelID, async webhook => {
return discord.snow.webhook.executeWebhook(webhook.id, webhook.token, data, {wait: true, disableEveryone: true})
})
return result
}
module.exports.sendMessage = sendMessage