有没有办法可以使用我的 Discord.py Rewrite Bot 解除禁令

Is There A Way I Can Unban Using My Discord.py Rewrite Bot

如何在 Discord.py Rewrite 中创建解禁命令 我想解决我的问题,因为没有 bot.unban 命令(也许是)而且播放器不在列表中所以我可以提及用户

编辑:

Traceback (most recent call last):
  File "C:\Users\BKhushi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\client.py", line 227, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\BKhushi\Desktop\gg\Discordgang.py", line 125, in on_command_error
    raise error
  File "C:\Users\BKhushi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\bot.py", line 814, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\BKhushi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 675, in invoke
    await self.prepare(ctx)
  File "C:\Users\BKhushi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 640, in prepare
    await self._parse_arguments(ctx)
  File "C:\Users\BKhushi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 561, in _parse_arguments
    transformed = await self.transform(ctx, param)
  File "C:\Users\BKhushi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 427, in transform
    return await self.do_conversion(ctx, converter, argument, param)
  File "C:\Users\BKhushi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 382, in do_conversion
    return await self._actual_conversion(ctx, converter, argument, param)
  File "C:\Users\BKhushi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 328, in _actual_conversion
    ret = await instance.convert(ctx, argument)
  File "C:\Users\BKhushi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\converter.py", line 158, in convert
    raise BadArgument('User "{}" not found'.format(argument))
discord.ext.commands.errors.BadArgument: User "@<552510634303029298>" not found```

如果您有一个 Member 对象表示被禁 Member,您可以使用 Member.unban. Most of the time, however, you'll instead have to get a User object representing that user and use Guild.unban:

from discord import User
from discord.ext.commands import Bot, guild_only

bot = Bot("!")

@bot.command(name='unban')
@guild_only()  # Might not need ()
async def _unban(ctx, id: int):
    user = await bot.fetch_user(id)
    await ctx.guild.unban(user)


bot.run("TOKEN")

我会考虑以下命令。我很抱歉在上述操作后它没有发送消息,以获取更多关于如何在 Discord.Py Rewrite 中写入的信息,我建议您观看 here!

  async def pardon(ctx, *, member):
      banned_users = await ctx.guild.bans()
      member_name, member_discriminator = member.split('#')

      for ban_entry in banned_users:
          user = ban_entry.banned_users

          if (user.name, user.discriminator) == (member_name, member_discriminator):
              await ctx.guild.unban(user)