diff --git a/assets/openapi.json b/assets/openapi.json
index a6ccabe4..5de9ed29 100644
--- a/assets/openapi.json
+++ b/assets/openapi.json
@@ -224,6 +224,20 @@
"message"
]
},
+ "PollUserAnswersSchema": {
+ "type": "object",
+ "properties": {
+ "answer_ids": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ }
+ },
+ "required": [
+ "answer_ids"
+ ]
+ },
"ActivitySchema": {
"type": "object",
"properties": {
@@ -24810,6 +24824,54 @@
]
}
},
+ "/channels/{channel_id}/polls/{poll_id}/answers/@me/": {
+ "put": {
+ "x-permission-required": "VIEW_CHANNEL",
+ "security": [
+ {
+ "bearer": []
+ }
+ ],
+ "requestBody": {
+ "required": true,
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/PollUserAnswersSchema"
+ }
+ }
+ }
+ },
+ "responses": {
+ "default": {
+ "description": "No description available"
+ }
+ },
+ "parameters": [
+ {
+ "name": "channel_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "channel_id"
+ },
+ {
+ "name": "poll_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "poll_id"
+ }
+ ],
+ "tags": [
+ "channels"
+ ]
+ }
+ },
"/channels/{channel_id}/pins/{message_id}": {
"put": {
"x-permission-required": "VIEW_CHANNEL",
diff --git a/assets/schemas.json b/assets/schemas.json
index c1f47bce..a6a73abf 100644
--- a/assets/schemas.json
+++ b/assets/schemas.json
@@ -207,6 +207,22 @@
],
"$schema": "http://json-schema.org/draft-07/schema#"
},
+ "PollUserAnswersSchema": {
+ "type": "object",
+ "properties": {
+ "answer_ids": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ }
+ },
+ "additionalProperties": false,
+ "required": [
+ "answer_ids"
+ ],
+ "$schema": "http://json-schema.org/draft-07/schema#"
+ },
"ActivitySchema": {
"type": "object",
"properties": {
diff --git a/src/api/routes/channels/#channel_id/polls/#poll_id/answers/@me.ts b/src/api/routes/channels/#channel_id/polls/#poll_id/answers/@me.ts
new file mode 100644
index 00000000..95660c30
--- /dev/null
+++ b/src/api/routes/channels/#channel_id/polls/#poll_id/answers/@me.ts
@@ -0,0 +1,72 @@
+/*
+ Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
+ Copyright (C) 2026 Spacebar and Spacebar Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import { Request, Response, Router } from "express";
+import { route } from "@spacebar/api/util/handlers/route";
+import { PollAnswerCount, PollUserAnswersSchema } from "@spacebar/schemas";
+import { Message } from "#database";
+import { DiscordApiErrors, ErrorList, FieldError, makeObjectErrorContent } from "#util";
+
+const router: Router = Router({ mergeParams: true });
+
+router.put("/", route({ requestBody: "PollUserAnswersSchema", permission: "VIEW_CHANNEL" }), async (req: Request, res: Response) => {
+ const payload = req.body as PollUserAnswersSchema;
+ const { poll_id } = req.params as { [key: string]: string };
+
+ const message = await Message.findOne({ where: { id: poll_id } });
+
+ if (!message || !message.poll || !message.poll.results) {
+ throw DiscordApiErrors.UNKNOWN_MESSAGE;
+ }
+
+ if (new Date() > new Date(message.poll.expiry)) {
+ throw DiscordApiErrors.POLL_EXPIRED;
+ }
+
+ if (!message.poll.allow_multiselect && payload.answer_ids.length > 1) {
+ const errors: ErrorList = {};
+ errors["answer_ids"] = makeObjectErrorContent("CANNOT_ADD_MULTIPLE_POLL_ANSWERS", "Multiple votes are not allowed for this poll.");
+ throw new FieldError(50035, "Invalid form body", errors);
+ }
+
+ const allAnswerCounts = message.poll.results.answer_counts as unknown as (Omit<PollAnswerCount, "me_voted"> & { voters: string[] })[];
+
+ for (const answer_id of payload.answer_ids) {
+ let answerCount = allAnswerCounts.find((a) => a.id === answer_id);
+
+ if (!answerCount) {
+ allAnswerCounts.push({ id: answer_id, count: 0, voters: [] });
+ answerCount = allAnswerCounts.find((a) => a.id === answer_id)!;
+ }
+
+ if (!answerCount.voters.includes(req.user_id)) {
+ answerCount.voters.push(req.user_id);
+ answerCount.count = answerCount.voters.length;
+ }
+ }
+
+ for (const answerCount of allAnswerCounts.filter((a) => !payload.answer_ids.includes(a.id))) {
+ answerCount.voters = answerCount.voters.filter((voter) => voter != req.user_id);
+ answerCount.count = answerCount.voters.length;
+ }
+
+ await message.save();
+ res.send();
+});
+
+export default router;
diff --git a/src/schemas/api/messages/Polls.ts b/src/schemas/api/messages/Polls.ts
index bd655561..d4ed3264 100644
--- a/src/schemas/api/messages/Polls.ts
+++ b/src/schemas/api/messages/Polls.ts
@@ -46,3 +46,7 @@ export interface PollAnswerCount {
count: number;
me_voted: boolean;
}
+
+export interface PollUserAnswersSchema {
+ answer_ids: string[];
+}
diff --git a/src/util/util/Constants.ts b/src/util/util/Constants.ts
index 5bfc1f72..4ffe9d12 100644
--- a/src/util/util/Constants.ts
+++ b/src/util/util/Constants.ts
@@ -659,6 +659,8 @@ export const DiscordApiErrors = {
STICKER_ANIMATION_DURATION_MAXIMUM: new ApiError("Sticker animation duration exceeds maximum of {} seconds", 170007, undefined, ["5"]),
AUTOMODERATOR_BLOCK: new ApiError("Message was blocked by automatic moderation", 200000),
BULK_BAN_FAILED: new ApiError("Failed to ban users", 500000),
+ POLL_VOTING_BLOCKED: new ApiError("Poll voting blocked", 520000),
+ POLL_EXPIRED: new ApiError("Poll expired", 520001),
//Other errors
UNKNOWN_VOICE_STATE: new ApiError("Unknown Voice State", 10065, 404),
|