Ошибка с разбаном :c nextcord

Рейтинг: 0Ответов: 1Опубликовано: 16.01.2023

Код

@commands.command()
@commands.has_permissions(ban_members=True)
async def unban(self, ctx, member, reason=None):
    banned_users = await ctx.guild.bans()
    channel = self.bot.get_channel(config.log_mes_channel_id)

    member_name, member_discriminator = member.split("#")
    for ban_entry in banned_users:
        user = ban_entry.user

        if (user.name, user.discriminator) == (member_name, member_discriminator):
            await ctx.guild.unban(user)
            embed = nextcord.Embed(title=f"Пользователя {user} разбанили", color=0xfac400)
            embed.set_author(name=f"{ctx.author}", icon_url=f"{ctx.author.avatar_url}")
            embed.set_footer(text=f"Silence. • {time.asctime()}")
            await channel.send(embed=embed)
            await ctx.channel.purge(limit=1)
            await ctx.send(embed=embed, delete_after=30)
            return

Ошибка

Ignoring exception in command unban:
Traceback (most recent call last):
  File "C:\Users\Krosrs\AppData\Local\Programs\Python\Python311\Lib\site-packages\nextcord\ext\commands\core.py", line 165, in wrapped
    ret = await coro(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\Krosrs\Desktop\SOLO\cogs\moder.py", line 72, in unban
    banned_users = await ctx.guild.bans()
                   ^^^^^^^^^^^^^^^^^^^^^^
TypeError: object BanIterator can't be used in 'await' expression

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Krosrs\AppData\Local\Programs\Python\Python311\Lib\site-packages\nextcord\ext\commands\bot.py", line 1381, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\Krosrs\AppData\Local\Programs\Python\Python311\Lib\site-packages\nextcord\ext\commands\core.py", line 948, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\Krosrs\AppData\Local\Programs\Python\Python311\Lib\site-packages\nextcord\ext\commands\core.py", line 174, in wrapped
    raise CommandInvokeError(exc) from exc
nextcord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: object BanIterator can't be used in 'await' expression

Ответы

▲ 1

Сообщение об ошибке указывает на наличие проблемы с линией:

Banned_users = await ctx.guild.bans()

ctx.guild.bans() возвращает объект BanIterator, который не является ожидаемым. Вместо использования await вы должны использовать для ban_entry в ctx.guild.bans():

Кроме того, вам необходимо убедиться, что элемент, переданный в качестве аргумента, является фактическим идентификатором пользователя, а не его именем. Это потому, что user = ban_entry.user даст вам объект запрещенного пользователя.