Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda