@commands.command()
async def ban(self, ctx, member, *, reason=None):
if len(member) == 18 and member.isdigit() == True: # бан по id участника
id = int(member)
user = await self.client.fetch_user(id)
await user.ban(reason = reason)
else: # бан по username участника
await member.ban(reason = reason)
import typing
...
@commands.command()
async def ban(self, ctx, member: typing.Union[discord.Member, int], *, reason=None):
# https://discordpy.readthedocs.io/en/stable/ext/commands/commands.html#typing-union
if isinstance(member, int):
member = discord.Object(member)
try:
await ctx.guild.ban(member, reason=reason) # https://discordpy.readthedocs.io/en/stable/api.html#discord.Guild.ban
except NotFound:
await ctx.send(f"Не найдено пользователя с ID {member.id}")