Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
How to delete picture in a channel | DJS

I would like to be able to delete an image sent automatically. But ONLY the pictures and not all the attachments.

I'm currently using message.attachments.size > 0. But I know that removes all attachments; what I don't want!

    async execute(message, client) {
    if (!message.guild || message.author.bot) return;

    if (message.channel.id === 'CHANNEL-ID' && message.attachments.size > 0) {
            message.delete()
    }

With my research, I came across a post explaining that it was enough to add filters; message.attachments.find(attachment => attachment.filename.endsWith('png') || attachment.filename.endsWith('jpg') || attachment.filename.endsWith('gif'))

But for me it does not work; shows me an error, it does not seem to recognize the .endsWith

node version: 16.13.2 | npm version: 8.1.2

Thanks in advance ! ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป

about 4 years ago ยท Santiago Gelvez
1 answers
Answer question

0

There is no property called filename in a MessageAttachment. Instead, it has a name property which I believe you can use. So you just need to replace the filename property with attachment.name

about 4 years ago ยท Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!