Skip to content

Commit

Permalink
Remove poll allowed_mention hack, add to webhooks & fix notes
Browse files Browse the repository at this point in the history
  • Loading branch information
DonovanDMC committed Apr 19, 2024
1 parent fc9445a commit b47ece0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
5 changes: 1 addition & 4 deletions lib/routes/Channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,7 @@ export default class Channels {
method: "POST",
path: Routes.CHANNEL_MESSAGES(channelID),
json: {
// HACK: currently, allowed_mentions cannot be sent along with a poll. Due to how this previously worked, allowed mentions was ALWAYS sent.
// We check if poll is not present (or if allowedMentions IS present, for future proofing), and don't send allowed_mentions
// ^ If fixed make sure to remove the note from the "poll" property in the CreateMessageOptions interface
allowed_mentions: options.poll === undefined || options.allowedMentions ? this.#manager.client.util.formatAllowedMentions(options.allowedMentions) : undefined,
allowed_mentions: this.#manager.client.util.formatAllowedMentions(options.allowedMentions),
attachments: options.attachments,
components: options.components ? this.#manager.client.util.componentsToRaw(options.components) : undefined,
content: options.content,
Expand Down
5 changes: 3 additions & 2 deletions lib/routes/Webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ export default class Webhooks {
* @caching This method **does not** cache its result.
*/
async editMessage<T extends AnyTextableChannel | Uncached>(webhookID: string, token: string, messageID: string, options: EditWebhookMessageOptions): Promise<Message<T>> {
const files = options.files;
const files = options.files ?? undefined;
if (options.files) {
delete options.files;
}
const query = new URLSearchParams();
if (options.threadID !== undefined) {
if (options.threadID) {
query.set("thread_id", options.threadID);
}
return this.#manager.authRequest<RawMessage>({
Expand Down Expand Up @@ -205,6 +205,7 @@ export default class Webhooks {
content: options.content,
embeds: options.embeds ? this.#manager.client.util.embedsToRaw(options.embeds) : undefined,
flags: options.flags,
poll: options.poll,
thread_name: options.threadName,
tts: options.tts,
username: options.username
Expand Down
7 changes: 2 additions & 5 deletions lib/types/channels.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,8 @@ export interface CreateMessageOptions {
/** Reply to a message. */
messageReference?: MessageReference;
/**
* A poll to send.
* @note As of [3/22/24](https://github.com/discord/discord-api-docs/pull/6746):
* * content, components, and many other fields cannot be sent alongside a poll.
* * * This means we cannot set `allowedMentions`. If in the future `content` can be sent alongside a poll, allowedMentions will not be set automatically, and must be set manually.
* * Messages with a poll cannot be edited.
* A poll to send. Messages with a poll cannot be edited.
* @note As of [4/18/24](https://github.com/discord/discord-api-docs/pull/6746#issuecomment-2064810908), `attachments` cannot be sent with polls.
*/
poll?: MessagePollOptions;
/** The IDs of up to 3 stickers from the current guild to send. */
Expand Down
1 change: 1 addition & 0 deletions lib/types/webhooks.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type { CreateMessageOptions, RawChannel } from "./channels";
import type { RawGuild } from "./guilds";
import type { RawUser } from "./users";
import type { Nullable } from "./misc";
import type { WebhookTypes } from "../Constants";

export interface RawWebhook {
Expand Down

0 comments on commit b47ece0

Please sign in to comment.