Выдаёт ошибку else:, не понимаю почему.
import discord
from discord.ext import commands
class BanCmd(commands.Cog):
def __init__(self, bot):
self.bot=bot
@discord.slash_command(description="Забанить пользователя.")
async def ban(self, ctx, member: discord.Option(
discord.Member, "Участник,которого забанить.",
name="участник", required=True
), reason: discord.Option(str, "Причина:",
name="причина", default="Не указана", requeired=False
)
):
await ctx.response.defer()
if member == ctx.author:
embed = discord.Embed(color=discord.Color.red(),
title="Ошибка!", description="Вы не можете забанить самого себя!"
)
await ctx.followup.send(embed=embed)
else:
embed = discord.Embed(title=f"Вы были забанены на сервере JustCube.",color=0x6CE5E8)
embed.add_field(name='Администратор:',value=ctx.author,inline=False)
embed.add_field(name='Участник:',value=member.mention,inline=False)
embed.add_field(name='Причина:',value=reason,inline=False)
embed.set_footer(text='Все права защищены - JustCube')
await member.send(embed =embed)
await member.ban(reason=reason)
embed = discord.Embed(title=f"Участник ID: {member.mention} был забанен на сервере JustCube.",color=0x6CE5E8)
embed.add_field(name='Администратор:',value=ctx.author,inline=False)
embed.add_field(name='Участник:',value=member.mention,inline=False)
embed.add_field(name='Причина:',value=reason,inline=False)
embed.set_footer(text='Все права защищены - JustCube')
await ctx.followup.send(embed=embed)
def setup(bot):
bot.add_cog(BanCmd(bot))
ошибка в консоли
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\cog.py", line 731, in _load_from_module_spec
spec.loader.exec_module(lib) # type: ignore
File "<frozen importlib._bootstrap_external>", line 879, in exec_module
File "<frozen importlib._bootstrap_external>", line 1017, in get_code
File "<frozen importlib._bootstrap_external>", line 947, in source_to_code
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Users\User\Desktop\JustCube\ext\ban.py", line 23
else:
^^^^
SyntaxError: invalid syntax
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\User\Desktop\JustCube\main.py", line 17, in <module>
bot.load_extension(extension)
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\cog.py", line 867, in load_extension
self._load_from_module_spec(spec, name)
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\cog.py", line 734, in _load_from_module_spec
raise errors.ExtensionFailed(key, e) from e
discord.errors.ExtensionFailed: Extension 'ext.ban' raised an error: SyntaxError: invalid syntax (ban.py, line 23)
Для продолжения нажмите любую клавишу . . .