Answer the question
In order to leave comments, you need to log in
How to leave a discord server by its id in discord.py?
I need to make the command ">server-leave [server id]", by which the discord bot will leave this server whose id I will specify when calling. I've been trying all day to solve this easy problem, but all the codes I've used from the documentation/questions from other users just don't work. Please, help. Here is the code I have and it is not working:
@bot.command(aliases=['server-leave'])
async def __leave_from_server(ctx, serverid = None):
if ctx.author.id in devlist:
if serverid == None:
await ctx.send(embed = discord.Embed(title = "Укажите id сервера"))
else:
try:
toleave = bot.get_guild(serverid)
await bot.leave_guild(toleave)
await ctx.send(embed = discord.Embed(title = "Успешно"))
except:
try:
toleave = bot.get_guild(serverid)
await toleave.leave()
await ctx.send(embed = discord.Embed(title = "Успешно"))
except:
await ctx.send(embed = discord.Embed(title = "Ошибка"))
Answer the question
In order to leave comments, you need to log in
bot.leave_guild
has not been in the given library for two years.DEV_LIST = [...]
def check_dev(ctx):
"""Check if command caller is dev"""
return ctx.author.id in DEV_LIST
@bot.command(name="server-leave")
@commands.check(check_dev)
async def __leave_from_server(ctx, server: discord.Guild = None):
"""Leave from selected server"""
if server:
await server.leave()
else:
await ctx.send("You need to specify server")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question