Discord.py Leaving a server(Discord.py离开服务器)
                            本文介绍了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离开服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
				 沃梦达教程
				
			本文标题为:Discord.py离开服务器
				
        
 
            
        
             猜你喜欢
        
	     - python-m http.server 443--使用SSL? 2022-01-01
 - pytorch 中的自适应池是如何工作的? 2022-07-12
 - 使用Heroku上托管的Selenium登录Instagram时,找不到元素';用户名'; 2022-01-01
 - 如何将一个类的函数分成多个文件? 2022-01-01
 - 沿轴计算直方图 2022-01-01
 - 如何在 python3 中将 OrderedDict 转换为常规字典 2022-01-01
 - python check_output 失败,退出状态为 1,但 Popen 适用于相同的命令 2022-01-01
 - 如何在 Python 的元组列表中对每个元组中的第一个值求和? 2022-01-01
 - 分析异常:路径不存在:dbfs:/databricks/python/lib/python3.7/site-packages/sampleFolder/data; 2022-01-01
 - padding='same' 转换为 PyTorch padding=# 2022-01-01
 
				
				
				
				