简体   繁体   中英

How do i make a command that make my bot leave from the server (discord.py)

I have a bot I need to add a command.leave that make him leave the server I have tried some codes but didn't help

@client.command()
async def leaveguild(ctx):
    await discord.Guild.leave()
    await ctx.send(f"I'm going , bye!")

discord.Guild is a class not an instance ( here's an explanation on what's the difference ). You need to get the instance from somewhere, the easiest way would be with ctx.guild , (the bot will leave the guild where the command was invoked). The rest of the code was correct.

@bot.command()
async def leave(ctx):
    await ctx.send("I am leaving this guild!")
    await ctx.guild.leave()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM