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

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

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 Report

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