Just use union for simplicity
This commit is contained in:
parent
16f91c3b47
commit
abd62bdba7
41
cogs/mod.py
41
cogs/mod.py
|
@ -1,9 +1,10 @@
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import utils
|
import utils
|
||||||
|
import typing
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
import asyncio
|
|
||||||
|
|
||||||
|
|
||||||
class Moderation(commands.Cog):
|
class Moderation(commands.Cog):
|
||||||
|
@ -47,43 +48,21 @@ class Moderation(commands.Cog):
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@utils.can_run(ban_members=True)
|
@utils.can_run(ban_members=True)
|
||||||
async def ban(self, ctx, member, *, reason=None):
|
async def ban(self, ctx, member: typing.Union[discord.Member, discord.Object], *, reason=None):
|
||||||
"""Used to ban a member
|
"""Used to ban a member
|
||||||
This can be used to ban someone preemptively as well.
|
This can be used to ban someone preemptively as well.
|
||||||
Provide the ID of the user and this should ban them without them being in the server
|
Provide the ID of the user and this should ban them without them being in the server
|
||||||
|
|
||||||
EXAMPLE: !ban 531251325312
|
EXAMPLE: !ban 531251325312
|
||||||
RESULT: That dude be banned"""
|
RESULT: That dude be banned"""
|
||||||
|
try:
|
||||||
# Lets first check if a user ID was provided, as that will be the easiest case to ban
|
await ctx.guild.ban(member, reason=reason)
|
||||||
if member.isdigit():
|
except discord.Forbidden:
|
||||||
try:
|
await ctx.send("But I can't, muh permissions >:c")
|
||||||
await ctx.bot.http.ban(member, ctx.guild.id, reason=reason)
|
except discord.HTTPException:
|
||||||
await ctx.send("\N{OK HAND SIGN}")
|
await ctx.send("Sorry, I failed to ban that user!")
|
||||||
except discord.Forbidden:
|
|
||||||
await ctx.send("But I can't, muh permissions >:c")
|
|
||||||
except discord.HTTPException:
|
|
||||||
await ctx.send("Sorry, I failed to ban that user!")
|
|
||||||
finally:
|
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
# If no ID was provided, lets try to convert what was given using the internal coverter
|
await ctx.send("\N{OK HAND SIGN}")
|
||||||
converter = commands.converter.MemberConverter()
|
|
||||||
try:
|
|
||||||
member = await converter.convert(ctx, member)
|
|
||||||
except commands.converter.BadArgument:
|
|
||||||
await ctx.send(
|
|
||||||
'{} does not appear to be a valid member. If this member is not in this server, please provide '
|
|
||||||
'their ID'.format(member))
|
|
||||||
return
|
|
||||||
# Now lets try actually banning the member we've been given
|
|
||||||
try:
|
|
||||||
await member.ban(reason=reason)
|
|
||||||
await ctx.send("\N{OK HAND SIGN}")
|
|
||||||
except discord.Forbidden:
|
|
||||||
await ctx.send("But I can't, muh permissions >:c")
|
|
||||||
except discord.HTTPException:
|
|
||||||
await ctx.send("Sorry, I failed to ban that user!")
|
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
|
|
Loading…
Reference in a new issue