python - 让我的机器人离开特定公会的命令: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})")
推荐阅读
- amazon-redshift - 在 Redshift 中动态将 Null 列更新为零
- c++ - 如何使字符串变量超过一个单词c ++?
- javascript - 应用程序脚本错误:无法读取未定义的属性“长度”
- javascript - 将属性作为对象中的函数
- google-sheets - 条件乘法 Google 表格
- python - 如何在python中绘制多个正弦波/波的总和
- php - 尝试在 xampp 中更新我的 php,现在我不断收到此错误
- mysql - 用另一个字符串替换所有等于一个字符串的列值
- go - 如何覆盖 protobuf 枚举值
- python - 某些单词是否禁止作为 dict() 语句中的键?