Discord.py离开服务器 [英] Discord.py Leaving a server

查看:16
本文介绍了Discord.py离开服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法访问我的机器人所在的某些测试服务器,我希望机器人离开它们,我的代码是

@bot.command()
@commands.is_owner()
async def guilds(ctx):
  await ctx.channel.purge(limit=1)
  guild = ""
  servers = bot.guilds
  for a in servers:
    guild += f"{a}
"
    if a == "Fleshy's server":
      b = a.id()
      await bot.leave(b)
  await ctx.author.send(guild)
当我使用它时,我没有得到任何错误,但它也不会离开肉体的服务器 这些是他所在的服务器 my server The Judas Cradle 7 test server yosh’s rock Fleshy's server Retronized Cafe Fleshy's server Fleshy's server Able's Hub

推荐答案

如果您希望通过知道工会名称来离开该工会,可以运行以下命令:

@bot.command()
async def leaveg(ctx, *, guild_name):
    guild = discord.utils.get(bot.guilds, name=guild_name) # Get the guild by name
    if guild is None:
        print("No guild with that name found.") # No guild found
        return
    await guild.leave() # Guild found
    await ctx.send(f"I left: {guild.name}!")
  • 我们使用*是为了还允许名称中包含空格
  • 导入from discord.utils import get

如果您知道服务器的ID,还可以运行以下命令:

@bot.command()
async def leave(ctx, guild_id):
    await bot.get_guild(int(guild_id)).leave()
    await ctx.send(f"I left: {guild_id}")
  • 导入from discord.utils import get
  • 请务必填入ID:leave ServerID

您还可以查看docs

这篇关于Discord.py离开服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆