Lukemul69
Lukemul69

Reputation: 187

Trying to make a bot leave a server by command

I am trying to make the bot leave a server with the ID, Command !leave

I get the error 'Bot' object has no attribute 'get_server'

Here is my script:

import discord
from discord.ext import commands

client = commands.Bot(command_prefix='!')

token = TOKEN HERE

@client.command()
async def leave(ctx, ID):
    toleave = client.get_server(ID)
    await client.leave_server(toleave)
    print("Left Server")

client.run(token)

Upvotes: 1

Views: 843

Answers (2)

PinkMenace
PinkMenace

Reputation: 46

This should work

@commands.command()
  async def leave(self, ctx, *, message=None ):
    guild_id = message
    guild = await self.client.get_guild(int(guild_id))
    channel = guild.system_channel
    await channel.send("Leaving this server due to misuse!")
    await guild.leave()

Upvotes: 0

Aplet123
Aplet123

Reputation: 35512

Since, discord.py 1.1, get_server has been renamed to get_guild, and leave_server has been moved to Guild.leave. So, your code would look something like:

toleave = client.get_guild(ID)
await toleave.leave()

Upvotes: 3

Related Questions