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

220
Vistas
Discord.js Snipe

I am trying to make a discord.js snipe command and I keep getting an error message: Cannot read properties of undefined (reading 'get'). I created command handlers and event handlers and everything works fine, even the messageDelete event. I get this message every time I run the command

Snipe command:

module.exports = {
    commands: ['snipe','sn','s'],
    requiredRoles: ['Members'],
    callback : (client, message, args) => {
        const msg = client.snipes.get(message.channel.id)
        if(!msg) return message.channel.send("There's nothing to snipe!")
        message.channel.send(`${msg.author} deleted: ${msg.content}`)
    }
}   

Index file:

const path = require('path')
const fs = require('fs')
const { Client, Intents, Collection } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

const config = require('./config.json');

require('./util/loadEvents')(client);

client.snipes = new Collection()

Event Handler:

const fs = require('fs');

module.exports = client => {
    fs.readdir("events/", (_err, files) => {
        files.forEach((file) => {
            if (!file.endsWith(".js")) return;
            const event = require(`../events/${file}`);
            let eventName = file.split(".")[0];
            client.on(eventName, event.bind(null, client));
            delete require.cache[require.resolve(`../events/${file}`)];
        });
    });
 }

And messageDelete Event:

module.exports = async (client,message) => {
    if(message.author.client) return;

    client.snipes.set(message.channel.id, {
        content: message.content,
        author: message.author.tag,
    })
}

All other commands work perfectly

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Make sure you pass the arguments in the correct order.

If you run the callback like this:

callback(message, arguments, arguments.join(' '), client); 

The order should be like this:

module.exports = {
  commands: ['snipe', 'sn', 's'],
  requiredRoles: ['Members'],
  callback: (message, arguments, joinedArguments, client) => {
    const msg = client.snipes.get(message.channel.id);
    if (!msg) return message.channel.send("There's nothing to snipe!");
    message.channel.send(`${msg.author} deleted: ${msg.content}`);
  }
};
about 4 years ago · Juan Pablo Isaza 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