Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

205
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda