discord.js
discord.js copied to clipboard
MessageManager#fetch has signatures, but none of those signatures are compatible with each other.
Which package is this bug report for?
discord.js
Issue description
On v14.3.0, when you fetch the messages of a channel through message.channel.messages.fetch()
without narrowing down the type of message.channel you get a Collection of Message
This is because, since the message manager can come from multiple types of channels, the boolean type parameter can be true or false, and those two are not compatible with each other, thus TS cannot infer the type of the resulting filtered Collection
Code sample
client.on("message", async message => {
(await message.channel.messages.fetch()).filter(m => m.author.id === message.author.id)
})
Package version
14.3.0
Node.js version
18.7.0
Operating system
Windows 11
Priority this issue should have
High (immediate attention needed)
Which partials do you have configured?
Not applicable (subpackage bug)
Which gateway intents are you subscribing to?
Not applicable (subpackage bug)
I have tested this issue on a development release
No response
I haven’t been able to update since v14.3.0 due to this issue. Can this be fixed asap please?
I was looking in to this. I initially thought to change TextBasedChannel
's definitions, but it's just an exclusion of Channel
, so modifying that wouldn't fix it. There's no BaseTextChannel
class I can modify. Each channel extends BaseChannel
which isn't always a TextChannel
so I can't change that.
Could anyone help point me in the right direction with this? Thanks!
I am also having the same issue with this. I am currently trying to make a purge command that clears messages from a user, and whenever I try to filter the messages to push them to an array and it filter out the author ID, it gives this error. Even on discord.js v14.7.1. Update: from what it seems, it's probably effecting versions newer than 14.3.0. Downgrading to 14.2.0 fixed it for me, so idk what the hell they did.
So looks like its effected by #8538
prob
So, I have found the issue. In order to use messages.filter
, the channel you are fetching messages from needs to be as TextChannel. Doing const messages = await (<Channel> as TextChannel).messages.fetch();
and then messages.filter()
should work.
That is not relevant to this issue. If you only care about text channels, you should check the channel's type.
That is not relevant to this issue. If you only care about text channels, you should check the channel's type.
Either way works, if you check the channels type is GuildText or casting it.
Except that is not a valid solution because this issue happens when you want to check the messages from any text based channel
I'm running into the same problem. Gotta @ts-ignore around this thing.
This issue has now also been resolved on TS as of v5.2 so for people in previous versions the fix will be to update TS. There is a caveat though that is explained in https://devblogs.microsoft.com/typescript/announcing-typescript-5-2-rc/#easier-method-usage-for-unions-of-arrays