Discord.js: Message.channel.bulkDelete() doesn't exist

Created on 23 Aug 2020  Â·  10Comments  Â·  Source: discordjs/discord.js

I'm using Typescript 4.0.2, the error is with the Typescript typings from what I can see. The error is:

error TS2339: Property 'bulkDelete' does not exist on type 'TextChannel | DMChannel | NewsChannel'. Property 'bulkDelete' does not exist on type 'DMChannel'.
client.on("message", async(msg: discord.Message) => {
if (msg.content == "!delete") {
let messages = await msg.channel.messages.fetch({ limit: 100 });
msg.channel.bulkDelete(messages);
}
})

Further details:

  • discord.js version: 12.3.1
  • Node.js version: 14.5.0
  • Operating system: Windows 8.1
  • Priority this issue should have – please be realistic and elaborate if possible: medium

Relevant client options:

  • partials: none
  • gateway intents: none
  • other: none
  • [ ] I have also tested the issue on latest master, commit hash:
unverified bug

Most helpful comment

The correct was to handle this in TypeScript is to cast the channel to the correct type, eg TextChannel or NewsChannel on which bulkDelete does exist.

All 10 comments

You never check if channel is a DM channel. You cannot bulkDelete there, so this is expected behavior.

I check if channel is a DM channel on my normal code, forgot to include it here it seems

Ok so seems like the problem is with the way I filter DM channels, somehow. I keep my commands in separate files and export a function from them. I then run the functions in message event. I also have a filter in message event that looks like this:

if (msg.channel.type == "dm") return;
if (msg.author.bot) return;
if (!msg.content.startsWith(config.prefix)) return;

I'm not sure why it's doing that, I'm guessing it's because i keep the commands in a separate file it can't detect that.

I fixed the problem by also adding the filter into the command.

@owoNUB any chance on a code example? New to discord.js and stuck on the same issue.

i literally went into the index.d.ts and slapped it there myself. probably not a good practice owo

if (message.channel.type === "dm") return;

anyways I think they meant this, didn't work for me, though

The correct was to handle this in TypeScript is to cast the channel to the correct type, eg TextChannel or NewsChannel on which bulkDelete does exist.

@monbrey that’s a hack. The types should be updated to ensure when we do the check listed above it resolves correct. Type guarding and such should work.

@monbrey that’s a hack. The types should be updated to ensure when we do the check listed above it resolves correct. Type guarding and such should work.

The entire typing file is "a hack" given that the code is written in JavaScript. We've tried before to resolve the issue of Channel typeguards but it causes issues in edge-cases.

When the library is eventually rewritten in TypeScript as the primary language, the issue will (should) be resolved.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DatMayo picture DatMayo  Â·  3Comments

tom-barnes picture tom-barnes  Â·  3Comments

tiritto picture tiritto  Â·  3Comments

Brawaru picture Brawaru  Â·  3Comments

PassTheMayo picture PassTheMayo  Â·  3Comments