Modlog API raises when trying to get a case if bot can't read message history in modlog channel #4587

Closed
opened 2020-11-10 00:40:34 +01:00 by Jackenmen · 0 comments
Jackenmen commented 2020-11-10 00:40:34 +01:00 (Migrated from github.com)

Other bugs

What were you trying to do?

Get a case with [p]case command.

What were you expecting to happen?

Get a case.

What actually happened?

I got an error:

Exception in command 'case'
Traceback (most recent call last):
  File "/home/ubuntu/red-venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/ubuntu/red-venv/lib/python3.8/site-packages/redbot/cogs/modlog/modlog.py", line 112, in case
    case = await modlog.get_case(number, ctx.guild, self.bot)
  File "/home/ubuntu/red-venv/lib/python3.8/site-packages/redbot/core/modlog.py", line 725, in get_case
    return await Case.from_json(mod_channel, bot, case_number, case)
  File "/home/ubuntu/red-venv/lib/python3.8/site-packages/redbot/core/modlog.py", line 556, in from_json
    message = await mod_channel.fetch_message(message_id)
  File "/home/ubuntu/red-venv/lib/python3.8/site-packages/discord/abc.py", line 970, in fetch_message
    data = await self._state.http.get_message(channel.id, id)
  File "/home/ubuntu/red-venv/lib/python3.8/site-packages/discord/http.py", line 241, in request
    raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50001): Missing Access

How can we reproduce this issue?

  1. Set modlog channel
  2. Make a case (either manually through API or by using some moderation command)
  3. Change modlog channel's permissions and forbid the bot from reading messages (or at least reading message history)
  4. Try getting the case with [p]case command.

This can be fixed by adding discord.Forbidden to catched errors in the code that fetches the message here:
github.com/Cog-Creators/Red-DiscordBot@48ec2dfee0/redbot/core/modlog.py (L555-L558)

# Other bugs #### What were you trying to do? Get a case with `[p]case` command. #### What were you expecting to happen? Get a case. #### What actually happened? I got an error: ```py Exception in command 'case' Traceback (most recent call last): File "/home/ubuntu/red-venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped ret = await coro(*args, **kwargs) File "/home/ubuntu/red-venv/lib/python3.8/site-packages/redbot/cogs/modlog/modlog.py", line 112, in case case = await modlog.get_case(number, ctx.guild, self.bot) File "/home/ubuntu/red-venv/lib/python3.8/site-packages/redbot/core/modlog.py", line 725, in get_case return await Case.from_json(mod_channel, bot, case_number, case) File "/home/ubuntu/red-venv/lib/python3.8/site-packages/redbot/core/modlog.py", line 556, in from_json message = await mod_channel.fetch_message(message_id) File "/home/ubuntu/red-venv/lib/python3.8/site-packages/discord/abc.py", line 970, in fetch_message data = await self._state.http.get_message(channel.id, id) File "/home/ubuntu/red-venv/lib/python3.8/site-packages/discord/http.py", line 241, in request raise Forbidden(r, data) discord.errors.Forbidden: 403 Forbidden (error code: 50001): Missing Access ``` #### How can we reproduce this issue? 1. Set modlog channel 2. Make a case (either manually through API or by using some moderation command) 3. Change modlog channel's permissions and forbid the bot from reading messages (or at least reading message history) 4. Try getting the case with `[p]case` command. --- This can be fixed by adding `discord.Forbidden` to catched errors in the code that fetches the message here: https://github.com/Cog-Creators/Red-DiscordBot/blob/48ec2dfee0d806f31cf4eada75de3226829b10eb/redbot/core/modlog.py#L555-L558
Sign in to join this conversation.
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot#4587
No description provided.