使我的机器人离开特定公会的命令:discord.py 重写

Command to make my bot leave a specific guild: discord.py rewrite

我想发出命令让机器人离开特定公会。用法是 -leave [guild]

我真的不知道该尝试什么,但我有点搞砸了一些论点;什么也没做

@commands.command(hidden=True)
@commands.is_owner()
async def leave(self, ctx, guild: discord.Guild):
    await self.bot.leave_guild(guild)
    await ctx.send(f":ok_hand: Left guild: {guild.name} ({guild.id})")

我收到以下错误:

AttributeError: module 'discord.ext.commands.converter' has no attribute 'GuildConverter'

我希望机器人离开公会并发送代码中显示的确认消息

公会没有内置转换器,所以你必须自己做:

@commands.command()
@commands.is_owner()
async def leave(self, ctx, *, guild_name):
    guild = discord.utils.get(self.bot.guilds, name=guild_name)
    if guild is None:
        await ctx.send("I don't recognize that guild.")
        return
    await self.bot.leave_guild(guild)
    await ctx.send(f":ok_hand: Left guild: {guild.name} ({guild.id})")