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

221
Views
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 answers
Answer question

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 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!