diff --git a/src/client/actions/TypingStart.js b/src/client/actions/TypingStart.js index af6bfadae617..689225587257 100644 --- a/src/client/actions/TypingStart.js +++ b/src/client/actions/TypingStart.js @@ -7,16 +7,15 @@ const { Events, TextBasedChannelTypes } = require('../../util/Constants'); class TypingStart extends Action { handle(data) { const channel = this.getChannel(data); - if (!channel) { - return; - } + if (!channel) return; + if (!TextBasedChannelTypes.includes(channel.type)) { this.client.emit(Events.WARN, `Discord sent a typing packet to a ${channel.type} channel ${channel.id}`); return; } const user = this.getUserFromMember(data); - if (channel && user) { + if (user) { /** * Emitted whenever a user starts typing in a channel. * @event Client#typingStart diff --git a/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js b/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js index 928ffcbca209..b49e311f4af5 100644 --- a/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +++ b/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js @@ -4,11 +4,11 @@ const { Events } = require('../../../util/Constants'); module.exports = (client, { d: data }) => { const channel = client.channels.cache.get(data.channel_id); - const time = new Date(data.last_pin_timestamp); + const time = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null; - if (channel && !Number.isNaN(time.getTime())) { + if (channel) { // Discord sends null for last_pin_timestamp if the last pinned message was removed - channel.lastPinTimestamp = time.getTime() ?? null; + channel.lastPinTimestamp = time; /** * Emitted whenever the pins of a channel are updated. Due to the nature of the WebSocket event, diff --git a/src/managers/GuildStickerManager.js b/src/managers/GuildStickerManager.js index 361a5f752717..24a61f6168ef 100644 --- a/src/managers/GuildStickerManager.js +++ b/src/managers/GuildStickerManager.js @@ -57,8 +57,9 @@ class GuildStickerManager extends CachedManager { * .catch(console.error); */ async create(file, name, tags, { description, reason } = {}) { - file = { ...(await MessagePayload.resolveFile(file)), key: 'file' }; - if (!file) throw new TypeError('REQ_RESOURCE_TYPE'); + const resolvedFile = await MessagePayload.resolveFile(file); + if (!resolvedFile) throw new TypeError('REQ_RESOURCE_TYPE'); + file = { ...resolvedFile, key: 'file' }; const data = { name, tags, description: description ?? '' }; diff --git a/src/structures/Channel.js b/src/structures/Channel.js index e3915eb3877e..6cc852031035 100644 --- a/src/structures/Channel.js +++ b/src/structures/Channel.js @@ -21,7 +21,7 @@ class Channel extends Base { constructor(client, data, immediatePatch = true) { super(client); - const type = ChannelTypes[data.type]; + const type = ChannelTypes[data?.type]; /** * The type of the channel * @type {ChannelType} diff --git a/src/structures/Message.js b/src/structures/Message.js index 1db22d4e1c79..aa51659a4ee1 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -45,7 +45,7 @@ class Message extends Base { */ this.deleted = false; - if (data) this._patch(data); + this._patch(data); } _patch(data) { diff --git a/typings/index.d.ts b/typings/index.d.ts index 3bd0b3dfcf15..7d8c60a0ae76 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -20,7 +20,6 @@ import { userMention, } from '@discordjs/builders'; import { Collection } from '@discordjs/collection'; -import { ChildProcess } from 'child_process'; import { APIActionRowComponent, APIApplicationCommand, @@ -47,10 +46,11 @@ import { RESTPostAPIApplicationCommandsJSONBody, Snowflake, } from 'discord-api-types/v9'; -import { EventEmitter } from 'events'; -import { AgentOptions } from 'https'; -import { Stream } from 'stream'; -import { MessagePort, Worker } from 'worker_threads'; +import { ChildProcess } from 'node:child_process'; +import { EventEmitter } from 'node:events'; +import { AgentOptions } from 'node:https'; +import { Stream } from 'node:stream'; +import { MessagePort, Worker } from 'node:worker_threads'; import * as WebSocket from 'ws'; import { ActivityTypes, diff --git a/typings/tests.ts b/typings/tests.ts index 1fa6a99ce020..33a6b04d8345 100644 --- a/typings/tests.ts +++ b/typings/tests.ts @@ -1,7 +1,6 @@ import { APIGuildMember, APIInteractionGuildMember, APIMessage } from 'discord-api-types/v9'; import { ApplicationCommand, - ApplicationCommandChannelOption, ApplicationCommandChannelOptionData, ApplicationCommandChoicesData, ApplicationCommandData, @@ -12,8 +11,6 @@ import { ApplicationCommandSubCommandData, ApplicationCommandSubGroupData, ButtonInteraction, - CacheFactory, - Caches, CategoryChannel, Client, ClientApplication, @@ -45,11 +42,9 @@ import { MessageCollector, MessageComponentInteraction, MessageEmbed, - MessageManager, MessageReaction, NewsChannel, Options, - PartialDMChannel, PartialTextBasedChannelFields, PartialUser, Permissions, @@ -71,7 +66,7 @@ import { User, VoiceChannel, } from '.'; -import { ApplicationCommandOptionTypes, ApplicationCommandTypes } from './enums'; +import { ApplicationCommandOptionTypes } from './enums'; const client: Client = new Client({ intents: Intents.FLAGS.GUILDS,