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

133
Vistas
Trouble making a command to force bot to leave a server. (Discord,js)
const Discord = require('discord.js')
const client = new Discord.Client({ws: {intents: Discord.Intents.ALL}});
const botowner = 'xxx'

exports.run = async (bot,message,args) => {
   let guildid = message.guild.id
 if (message.author.id = botowner) {
    toleave = client.get_server(guildid)
    await client.leave_server(toleave)
 } else {message.channel.send("You are not the bot owner")}
    
}

exports.help = {
    name: ['leavediscordserver']
    }

Whenever I run this code the following shows up:enter image description here

Not sure why this is happening.

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

0

The error message tells you all you need to know. You attempt to use a function called get_server(), but this function does not exist ergo you cannot use it.

A discord server in Discord.js is referred to as a Guild so to get your guild you can just call const guild = client.guilds.cache.fetch(guildid) and to leave it all you have to do is call guild.leave().

As a separate issue, a comparison in an if statement is made with 2 equal signs == not 1 as you did in your if (message.author.id = botowner) line.

about 4 years ago · Juan Pablo Isaza Denunciar

0

var guildID = client.guilds.cache.get(args[0]) //your argument would be the server id
    if (message.author.id == botowner) { // use == to check if author and bot owner id match
    await guildID.leave() // waiting for bot to leave the server
 } else {message.channel.send("You are not the bot owner")}
    
}
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