diff --git a/Robocop.py b/Robocop.py index f79ad0b..2ef0c2e 100755 --- a/Robocop.py +++ b/Robocop.py @@ -104,9 +104,11 @@ async def on_error(event_method, *args, **kwargs): @bot.event async def on_command_error(ctx, error): + error_text = str(error) + log.error(f"Error with \"{ctx.message.content}\" from " f"\"{ctx.message.author} ({ctx.message.author.id}) " - f"of type {type(error)}: {error}") + f"of type {type(error)}: {error_text}") if isinstance(error, commands.NoPrivateMessage): return await ctx.send("This command doesn't work on DMs.") @@ -129,6 +131,13 @@ async def on_command_error(ctx, error): return await ctx.send(f"{ctx.author.mention}: Check failed. " "You might not have the right permissions " "to run this command.") + elif isinstance(error, commands.CommandInvokeError) and\ + ("Cannot send messages to this user" in error_text): + return await ctx.send(f"{ctx.author.mention}: I can't DM you.\n" + "You might have me blocked or have DMs " + f"blocked globally or for {ctx.guild.name}.\n" + "Please resolve that, then " + "run the command again.") elif isinstance(error, commands.CommandNotFound): # Nothing to do when command is not found. return diff --git a/cogs/admin.py b/cogs/admin.py index 199b960..2f6b16e 100644 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -13,9 +13,13 @@ class AdminCog: self.previous_eval_code = None def check_if_staff(ctx): + if not ctx.guild: + return False return any(r.id in config.staff_role_ids for r in ctx.author.roles) def check_if_bot_manager(ctx): + if not ctx.guild: + return False return any(r.id == config.bot_manager_role_id for r in ctx.author.roles) @commands.guild_only() diff --git a/cogs/basic.py b/cogs/basic.py index b74d94b..143708d 100644 --- a/cogs/basic.py +++ b/cogs/basic.py @@ -22,6 +22,7 @@ class Basic: await ctx.send(f"{targetuser.mention}: A link to the rules " f"can be found here: {config.rules_url}") + @commands.guild_only() @commands.command() async def membercount(self, ctx): """Prints the member count of the server.""" diff --git a/cogs/lockdown.py b/cogs/lockdown.py index d6c4055..9ce5ce5 100644 --- a/cogs/lockdown.py +++ b/cogs/lockdown.py @@ -8,6 +8,8 @@ class Lockdown: self.bot = bot def check_if_staff(ctx): + if not ctx.guild: + return False return any(r.id in config.staff_role_ids for r in ctx.author.roles) @commands.guild_only() diff --git a/cogs/meme.py b/cogs/meme.py index e2acaa7..9694aae 100644 --- a/cogs/meme.py +++ b/cogs/meme.py @@ -14,6 +14,8 @@ class Meme: self.bot = bot def check_if_staff_or_ot(ctx): + if not ctx.guild: + return True is_ot = (ctx.channel.name == "off-topic") is_staff = any(r.id in config.staff_role_ids for r in ctx.author.roles) return (is_ot or is_staff) diff --git a/cogs/mod.py b/cogs/mod.py index f29122e..852d72e 100644 --- a/cogs/mod.py +++ b/cogs/mod.py @@ -10,9 +10,13 @@ class ModCog: self.bot = bot def check_if_staff(ctx): + if not ctx.guild: + return False return any(r.id in config.staff_role_ids for r in ctx.author.roles) def check_if_target_is_staff(self, target): + if not ctx.guild: + return False return any(r.id in config.staff_role_ids for r in target.roles) async def add_restriction(self, member, rst): @@ -190,7 +194,7 @@ class ModCog: @commands.guild_only() @commands.bot_has_permissions(ban_members=True) @commands.check(check_if_staff) - @commands.command() + @commands.command(alias=["softban"]) async def hackban(self, ctx, target: int, *, reason: str = ""): """Bans a user with their ID, doesn't message them, staff only.""" target_user = await self.bot.get_user_info(target) diff --git a/cogs/verification.py b/cogs/verification.py index a9eb2db..da2200e 100644 --- a/cogs/verification.py +++ b/cogs/verification.py @@ -104,6 +104,8 @@ class Verification: self.bot = bot def check_if_staff(ctx): + if not ctx.guild: + return False return any(r.id in config.staff_role_ids for r in ctx.author.roles) @commands.check(check_if_staff)