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离开服务器


基础教程推荐
猜你喜欢
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 包装空间模型 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01