При вводе команды /bans выдаёт ошибку в консоль , но не сразу. Все права у бота есть, при вводе команды бана, он банит участника спокойно без всяких вопросов.
Console:
Ignoring exception in command bans:
Traceback (most recent call last):
File "C:\Users\студент\Desktop\Taburet\venv\Lib\site-packages\discord\commands\core.py", line 131, in wrapped
ret = await coro(arg)
^^^^^^^^^^^^^^^
File "C:\Users\студент\Desktop\Taburet\venv\Lib\site-packages\discord\commands\core.py", line 1013, in _invoke
await self.callback(ctx, **kwargs)
File "C:\Users\студент\Desktop\Taburet\main.py", line 75, in bans
for entry in bans:
TypeError: 'BanIterator' object is not iterable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\студент\Desktop\Taburet\venv\Lib\site-packages\discord\bot.py", line 1130, in invoke_application_command
await ctx.command.invoke(ctx)
File "C:\Users\студент\Desktop\Taburet\venv\Lib\site-packages\discord\commands\core.py", line 376, in invoke
await injected(ctx)
File "C:\Users\студент\Desktop\Taburet\venv\Lib\site-packages\discord\commands\core.py", line 139, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: TypeError: 'BanIterator' object is not iterable
Сам код команды:
bot.slash_command(guild_ids = servers, name = "ban", description = "Bans a member")
@commands.has_permissions(ban_members = True, administrator = True)
async def ban(ctx, member: Option(discord.Member, description="Who do you want to ban?"), reason: Option(str, description = "Why?", required = False)):
if member.id == ctx.author.id: #checks to see if they're the same
await ctx.respond("BRUH! You can't ban yourself!")
elif member.guild_permissions.administrator:
await ctx.respond("Stop trying to ban an admin! :rolling_eyes:")
else:
if reason == None:
reason = f"None provided by {ctx.author}"
await member.ban(reason = reason)
await ctx.respond(f"<@{ctx.author.id}>, <@{member.id}> has been banned successfully from this server!\n\nReason: {reason}")
@ban.error
async def banerror(ctx, error):
if isinstance(error, MissingPermissions):
await ctx.respond("You need Ban Members and Administrator permissions to do this!")
else:
await ctx.respond("Something went wrong...") #most likely due to missing permissions
raise error
@bot.slash_command(guild_ids = servers, name = "bans", description = "Get a list of members who are banned from this server!")
@commands.has_permissions(ban_members = True)
async def bans(ctx):
await ctx.defer()
bans = ctx.guild.bans()
embed = discord.Embed(title = f"List of Bans in {ctx.guild}", timestamp = datetime.now(), color = discord.Colour.red())
for entry in bans:
if len(embed.fields) >= 25:
break
if len(embed) > 5900:
embed.add_field(name = "Too many bans to list")
else:
embed.add_field(name = f"Ban", value = f"Username: {entry.user.name}#{entry.user.discriminator}\nReason: {entry.reason}\nUser ID: {entry.user.id}\nIs Bot: {entry.user.bot}", inline = False)
await ctx.respond(embed = embed)