Search code examples
javascriptbotsdiscord.jssenddefined

Bot has roblem with sending/editing embed messages


So i already asked around here and there but i dont find out how to fix eroor: ReferenceError: send is not defined In the non embed version everything works fine but here it just won't.

module.exports = {
        name: 'lat2',
        description: 'Let the Bot display latency/Response Time and API latency/"Remote Response time"',
        execute(message, args) {
            const Discord = require('discord.js');
            let Embed1 = new Discord.MessageEmbed()
                .setColor(0x0099ff)
                .setDescription("Pinging...")

            let Embed2 = new Discord.MessageEmbed()
                .setColor(0x0099ff)
                .setTitle("Latencies")
                .setDescription(`Latency/Response Time: ${send.createdTimestamp - message.createdTimestamp}ms\nAPI latency/"Remote Response time": ${Math.round(message.client.ws.ping)}ms`)

            msg.channel.send(Embed1).then(msg => {
                msg.edit(Embed2);
            });
        }
    };

Solution

  • The problem isn't sending the message, it's complaining about the ${send.createdTimestamp}, because you didn't define "send" anywhere there. Try replacing it with message.createdAt

    To still get the Latency, try this:

    module.exports = {
            name: 'lat2',
            description: 'Let the Bot display latency/Response Time and API latency/"Remote Response time"',
            execute(message, args) {
                const Discord = require('discord.js');
                let Embed1 = new Discord.MessageEmbed()
                    .setColor(0x0099ff)
                    .setDescription("Pinging...")
    
                msg.channel.send(Embed1).then(m => {
    
                let Embed2 = new Discord.MessageEmbed()
                    .setColor(0x0099ff)
                    .setTitle("Latencies")
                    .setDescription(`Latency/Response Time: ${m.createdTimestamp - message.createdTimestamp}ms\nAPI latency/"Remote Response time": ${Math.round(message.client.ws.ping)}ms`)
                    m.edit(Embed2);
                });
            }
        };