feat(plugins/validations): sendMessage at least one prop + support stickers (#2467)

When creating a message, apps must provide a value for **at least one of** `content`, `embeds`, `sticker_ids`, `components`, or `files[n]`.
https://discord.com/developers/docs/resources/channel#create-message-jsonform-params
This commit is contained in:
LTS20050703
2022-09-14 23:53:49 +07:00
committed by GitHub
parent 1bbb992a71
commit bc44a2feb1
2 changed files with 10 additions and 0 deletions

View File

@@ -117,6 +117,7 @@ export async function sendMessage(bot: Bot, channelId: bigint, options: CreateMe
},
}
: {}),
sticker_ids: options.stickerIds?.map((sticker) => sticker.toString()),
},
);
@@ -152,4 +153,6 @@ export interface CreateMessage {
file?: FileContent | FileContent[];
/** The components you would like to have sent in this message */
components?: MessageComponents;
/** IDs of up to 3 stickers in the server to send in the message */
stickerIds?: [bigint] | [bigint, bigint] | [bigint, bigint, bigint];
}

View File

@@ -1,5 +1,6 @@
import { AllowedMentionsTypes, Bot } from "../../deps.ts";
import { validateComponents } from "../components.ts";
import { messages } from "./mod.ts";
export function sendMessage(bot: Bot) {
const sendMessage = bot.helpers.sendMessage;
@@ -54,6 +55,12 @@ export function sendMessage(bot: Bot) {
if (content.components) validateComponents(bot, content.components);
if (content.content || content.embeds || content.components || content.file || content.stickerIds) {
throw new Error(
"When sending a message, you must provide a value for at least one of content, embeds, stickerIds, components, or file.",
);
}
return sendMessage(channelId, content);
};
}