From 1319e0c04e21bb07badede04297bbc4cf8d61854 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Sat, 23 Apr 2022 01:28:03 +1000 Subject: [PATCH] Can no longer send messages to channel types that do not support it ( categories, voice etc ) --- api/src/routes/channels/#channel_id/messages/index.ts | 5 +++++ util/src/entities/Channel.ts | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/api/src/routes/channels/#channel_id/messages/index.ts b/api/src/routes/channels/#channel_id/messages/index.ts index af0ae32d..34cc5ff8 100644 --- a/api/src/routes/channels/#channel_id/messages/index.ts +++ b/api/src/routes/channels/#channel_id/messages/index.ts @@ -183,6 +183,9 @@ router.post( } } const channel = await Channel.findOneOrFail({ where: { id: channel_id }, relations: ["recipients", "recipients.user"] }); + if (!channel.isWritable()) { + throw new HTTPError(`Cannot send messages to channel of type ${channel.type}`, 400) + } const embeds = body.embeds || []; if (body.embed) embeds.push(body.embed); @@ -220,6 +223,8 @@ router.post( }) ); } + + //Fix for the client bug delete message.member diff --git a/util/src/entities/Channel.ts b/util/src/entities/Channel.ts index 4bf81901..c516e6a1 100644 --- a/util/src/entities/Channel.ts +++ b/util/src/entities/Channel.ts @@ -352,6 +352,17 @@ export class Channel extends BaseClass { isDm() { return this.type === ChannelType.DM || this.type === ChannelType.GROUP_DM; } + + // Does the channel support sending messages ( eg categories do not ) + isWritable() { + const disallowedChannelTypes = [ + ChannelType.GUILD_CATEGORY, + ChannelType.GUILD_VOICE, // TODO: Remove this when clients can send messages to voice channels on discord.com + ChannelType.GUILD_STAGE_VOICE, + ChannelType.VOICELESS_WHITEBOARD, + ]; + return disallowedChannelTypes.indexOf(this.type) == -1; + } } export interface ChannelPermissionOverwrite {