Redjumpman / Jumper-Plugins

Python Modules for Discord bot
GNU General Public License v3.0
131 stars 95 forks source link

[Shop] Guild admin role check in dm's #186

Closed aikaterna closed 4 years ago

aikaterna commented 5 years ago

To repro: Bank is global. Set a permissions rule (I used a global default: permissions setdefaultglobalrule deny) Use a non-bot owner account. Use a shop command in dm's (I used just [p]shop) The pred check in shop is looking for a guild admin role in dm's.

Ignoring exception in on_command_error
Traceback (most recent call last):
  File "/.../lib/python3.7/site-packages/discord/client.py", line 270, in _run_event
    await coro(*args, **kwargs)
  File "/.../lib/python3.7/site-packages/redbot/core/events.py", line 208, in on_command_error
    c async for c in RedHelpFormatter.help_filter_func(ctx, bot.walk_commands())
  File "/.../lib/python3.7/site-packages/redbot/core/events.py", line 207, in <setcomp>
    commands={
  File "/.../lib/python3.7/site-packages/redbot/core/commands/help.py", line 444, in help_filter_func
    if await obj.can_see(ctx):
  File "/.../lib/python3.7/site-packages/redbot/core/commands/commands.py", line 329, in can_see
    ctx, check_all_parents=True, change_permission_state=False
  File "/.../lib/python3.7/site-packages/redbot/core/commands/commands.py", line 230, in can_run
    ret = await super().can_run(ctx)
  File "/.../lib/python3.7/site-packages/discord/ext/commands/core.py", line 935, in can_run
    return await discord.utils.async_all(predicate(ctx) for predicate in predicates)
  File "/.../lib/python3.7/site-packages/discord/utils.py", line 320, in async_all
    elem = await elem
  File "/root/.local/share/Red-DiscordBot/cogs/CogManager/cogs/shop/shop.py", line 41, in pred
    admin_role = await ctx.bot.db.guild(ctx.guild).admin_role()
  File "/.../lib/python3.7/site-packages/redbot/core/config.py", line 881, in guild
    return self._get_base_group(self.GUILD, str(guild.id))
AttributeError: 'NoneType' object has no attribute 'id'
mlucap commented 4 years ago

This throws an error because there is no guild id in dms. Not 100% familiar with this bot but an easy fix is to just check if the message is in dms and not allow the command.

aikaterna commented 4 years ago

If I wanted to fix it that way I would have.