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

165
Views
Cannot read properties of undefined (reading 'send') (Discord.js v13)

i have been trying to make a leaveserver code for my bot, but i always get the error message Cannot read properties of undefined (reading 'send') I really wanna know why it always says the error messages! Please help me! Thanks!

const Discord = require("discord.js")
const rgx = /^(?:<@!?)?(\d+)>?$/;

var self = this

const OWNER_ID = require("../../config.json").OWNER_ID;
module.exports = {
  name: "leaveserver",
  description: "leavs a server",
  run: async (client, message, args) => {
    if (!OWNER_ID)
      return message.channel.send("This command is Owner Only")},
      
async run(message, args) {
    const guildId = args[0];
    if (!rgx.test(guildId))
    return message.channel.send("Please Provide a valid server id!")
    const guild = message.client.guild.cache.get(guildId);
    if (!guild) return message.channel.send(message, 0, 'Unable to find server, please check the provided ID');
    await guild.leave();
    const embed = new MessageEmbed()
      .setTitle('Leave Guild')
      .setDescription(`I have successfully left **${guild.name}**.`)
      .setFooter(message.member.displayName,  message.author.displayAvatarURL({ dynamic: true }))
      .setTimestamp()
      .setColor(message.guild.me.displayHexColor);
    message.channel.send({embeds: [embed]});
  } 
}

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try this code

const {
    MessageEmbed
} = require("discord.js")
const rgx = /^(?:<@!?)?(\d+)>?$/;
const OWNER_ID = require("../../config.json").OWNER_ID;

module.exports = {
    name: "leaveserver",
    description: "leaves a server",
    run: async (client, message, args) => {
        const guildId = args[0];
        const guild = message.client.guilds.cache.get(guildId);

        if (!OWNER_ID) return message.channel.send("This command is Owner Only");

        if (!rgx.test(guildId)) return message.channel.send("Please Provide a valid server id!")
        if (!guild) return message.channel.send(message, 0, 'Unable to find server, please check the provided ID');

        await guild.leave();
        
        const embed = new MessageEmbed()
            .setTitle('Leave Guild')
            .setDescription(`I have successfully left **${guild.name}**.`)
            .setFooter({
                text: message.member.displayName,
                iconURL: message.author.displayAvatarURL({
                    dynamic: true
                })
            })
            .setTimestamp()
            .setColor(message.guild.me.displayHexColor)
        message.channel.send({
            embeds: [embed]
        })
    }
}

Removed the duplicated async run(message, args) {

about 4 years ago · Juan Pablo Isaza Report

0

Try to do this:

const client = new Discord.Client({intents:
["GUILDS", "GUILD_MESSAGES"]});

client.on("message" , msg => {

   await guild.leave();
    const embed = new MessageEmbed()
      .setTitle('Leave Guild')
      .setDescription(`I have successfully left **${guild.name}**.`)
      .setFooter(msg.member.displayName,  msg.author.displayAvatarURL({ dynamic: true }))
      .setTimestamp()
      .setColor(msg.guild.me.displayHexColor);
    msg.channel.send({embeds: [embed]});
})
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!