python-discord / bot

The community bot for the Python Discord community
https://pythondiscord.com
MIT License
1.34k stars 666 forks source link

Handle Discord's rejection of off-topic channel names due to disallowed words #2282

Closed MarkKoz closed 1 month ago

MarkKoz commented 1 year ago

Sentry Issue: BOT-38K

Summary

Discord must have recently added a new feature which rejects channel names if they contain certain words they don't like. This is a problem for our automated renaming of off-topic channels, which has some names with words that are no longer allowed. The first event of the Sentry issue above was caused by the name "ot0-welcome-and-fuck-you", for example.

Solutions

There are several ways to mitigate this:

  1. Catch the error and keep trying new random channel names until one succeeds. If error code 50035 is too broad, then the code will have to match the error text. The rejected words could also be deleted from the database. Alternatively, we could be notified about rejections so we can rename them to comply with Discord's wishes. For example, replacing "fuck" with "frick".
  2. When a new name gets added, attempt to create/rename a temporary channel to test that it's a valid name. Display an error to the command invoker if Discord rejects the name.
  3. If we can somehow get and maintain an up-to-date list of disallowed words, check against that before adding new names to the database (and remove existing records which violate it). This would ideally be done by the API, in which case this issue should probably be moved to the python-discord/site.

Solution № 3 is ideal, but I don't think the list is publicly available. Thus, I'm leaning towards № 1. I'd rather not delete the rejected names because:

  1. It would just suck to lose names that have accumulated over many years.
  2. Discord may revert this feature (or Python Discord is no longer in Server Discovery, which is unlikely I suppose).

Alternative proposals are welcome.

Other Affected Features

I believe the only other feature that creates/renames channels is the help system, but it uses fruit names, so I think we don't have to worry there. Modmail may suffer from this problem, but it's out of scope for this issue.

Traceback

HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In name: Contains words not allowed for servers in Server Discovery.
  File "discord/ext/tasks/__init__.py", line 239, in _loop
    await self.coro(*args, **kwargs)
  File "bot/exts/fun/off_topic_names.py", line 65, in update_names
    await channel_0.edit(name=OTN_FORMATTER.format(number=0, name=channel_0_name))
  File "discord/channel.py", line 371, in edit
    payload = await self._edit(options, reason=reason)
  File "discord/abc.py", line 490, in _edit
    return await self._state.http.edit_channel(self.id, reason=reason, **options)
  File "discord/http.py", line 507, in request
    raise HTTPException(response, data)

Unhandled exception in internal background task "update_names".
vivekashok1221 commented 1 year ago

If option 3 isn't possible, option 1.b is a good compromise (get notified so that we can either change or delete the ot name).

Edit: We could also (probably) use non-latin characters in the offending channel name but I'm not very enthusiastic about this solution as it involves circumventing restrictions put by Discord.

MrHemlock commented 1 year ago

I would think just going through and curating the list we have now and just clean it up rather than have these on the fly fixes. Probably not a great look for us to have fuck in one of our channel names anyway. Then I guess from there just have a regular filter on new additions.

A low tech solution makes more sense to me for something like this.

MarkKoz commented 1 year ago

@MrHemlock We don't know which words are disallowed. Thus, we cannot prevent new invalid names from being added.

MrHemlock commented 1 year ago

Fair. Just feels like more maintenance to have to have to add and potentially remove in future. Out of the three, 1 sounds the better solution given the current circumstances.

I do also think we should go through and curate the list again anyway. Couldn't hurt.

MarkKoz commented 1 year ago

Just feels like more maintenance to have to have to add and potentially remove in future.

Being concerned about complexity is valid. With that in mind, we could do one of the following (assuming we go with solution 1):

  1. Only retry. Don't delete invalid names and don't notify about invalid names.
  2. Just catch the error and do nothing. Downside: one of the channel names won't change.

In both cases, there is the additional downside of not knowing that some names are never being used, and thus not being able to fix them.

MrHemlock commented 1 year ago

Something like a message in Mod alerts or Dev alerts would probably be sufficient for 2. Handle that case (delete, modify, etc.) and either trigger the try again or just let it sit until the next go.

wookie184 commented 1 year ago

I would be for sending a message somewhere and retrying. I also wouldn't mind not retrying, but I don't think it should add too much complexity to include it.