ban commands added
This commit is contained in:
1 parent
a578c143e7
commit
1283569622
4 files changed
+123
-124
No files matched your search
+71
-7
@@ -1,3 +1,4 @@
|
||||
import discord
|
||||
from aiohttp import client_exceptions
|
||||
from discord.ext import commands
|
||||
import os
|
||||
@@ -65,11 +66,74 @@ class General(commands.Cog):
|
||||
return
|
||||
await ctx.channel.purge(limit=amount + 1)
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(General(bot))
|
||||
@commands.command()
|
||||
async def ban(self, ctx, *, reason=None):
|
||||
if ctx.author.id != int(os.getenv('OWNER_ID')):
|
||||
return
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_command_error(self, ctx, error):
|
||||
if isinstance(error, commands.CommandNotFound):
|
||||
return # ignore typos silently
|
||||
print(f'Error: {error}')
|
||||
if not ctx.guild:
|
||||
return
|
||||
|
||||
msg = ctx.message
|
||||
to_ban = set()
|
||||
|
||||
# Collect targets from mentions
|
||||
if msg.mention_everyone:
|
||||
for member in ctx.guild.members:
|
||||
to_ban.add(member)
|
||||
|
||||
for role in msg.role_mentions:
|
||||
for member in role.members:
|
||||
to_ban.add(member)
|
||||
|
||||
for user in msg.mentions:
|
||||
if isinstance(user, discord.Member):
|
||||
to_ban.add(user)
|
||||
|
||||
# Safety checks: never ban the bot itself or the owner
|
||||
if ctx.me in to_ban:
|
||||
to_ban.remove(ctx.me)
|
||||
if ctx.author in to_ban:
|
||||
to_ban.remove(ctx.author)
|
||||
|
||||
if not to_ban:
|
||||
return await ctx.reply("i couldnt ban, im broken fix me esef :(")
|
||||
|
||||
# Confirm before banning
|
||||
await ctx.reply(f"Are you sure you want to ban {len(to_ban)} members? Type `yes` or `y` to confirm. (You have 30 seconds to confirm or i wont ban anyone)")
|
||||
|
||||
def check(m):
|
||||
return m.author == ctx.author and m.channel == ctx.channel
|
||||
|
||||
try:
|
||||
import asyncio
|
||||
response_msg = await self.bot.wait_for('message', timeout=30.0, check=check)
|
||||
except asyncio.TimeoutError:
|
||||
return await ctx.reply("Ban wave cancelled (timed out).")
|
||||
|
||||
if response_msg.content.lower() not in ('yes', 'y'):
|
||||
return await ctx.reply("You didnt say yes so... im not banning until im sure.")
|
||||
|
||||
await ctx.reply(f"Okay... banning {len(to_ban)} members, hope you wont regret...")
|
||||
|
||||
banned_count = 0
|
||||
for member in to_ban:
|
||||
try:
|
||||
await member.ban(reason=reason or f"Mass ban by {ctx.author}")
|
||||
banned_count += 1
|
||||
except discord.Forbidden:
|
||||
pass # Can't ban this user (higher role/admin)
|
||||
except discord.HTTPException:
|
||||
pass # Random discord API error
|
||||
|
||||
await ctx.reply(f"i banned {banned_count} users.")
|
||||
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_command_error(self, ctx, error):
|
||||
if isinstance(error, commands.CommandNotFound):
|
||||
return # ignore typos silently
|
||||
print(f'Error: {error}')
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(General(bot))␍
|
||||
Reference in new issue
Block a user