modmail-dev / Modmail

A Discord bot that functions as a shared inbox between staff and members, similar to Reddit's Modmail.
https://docs.modmail.dev
GNU Affero General Public License v3.0
1.57k stars 4.59k forks source link

[BUG] Users with names containing words banned by Discord server discovery/community cannot open threads #2934

Closed patrickklaeren closed 3 years ago

patrickklaeren commented 3 years ago

Describe the bug When a user has a word that is banned by Discord server discovery community guidelines (I can add a few, but you can probably imagine which terms), a thread cannot be opened by the user because the Discord API does not want to create a channel with the user's name.

Bot Info Bot version (check with @modmail about): 3.6.2 Host method (Heroku, self-host, etc): self hosted

To Reproduce Steps to reproduce the behavior:

  1. Have server enrolled in server discovery
  2. Have anyone with a username containing a banned term message the bot
  3. Check log channel:

image

Error Logs

discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In name: Contains words not allowed for servers in Server Discovery.
2021-01-11 08:45:24 __main__[762] - ERROR: Failed to send message:
Traceback (most recent call last):
  File "/app/bot.py", line 760, in process_dm_modmail
    await thread.send(message)
  File "/app/core/thread.py", line 713, in send
    self.bot.loop.create_task(self.bot.api.append_log(message, channel_id=self.channel.id))
AttributeError: 'NoneType' object has no attribute 'id'
2021-01-11 08:45:30 core.thread[102] - CRITICAL: An error occurred while creating a thread.
Traceback (most recent call last):
  File "/app/core/thread.py", line 95, in setup
    channel = await self.bot.modmail_guild.create_text_channel(
  File "/app/.heroku/python/lib/python3.9/site-packages/discord/guild.py", line 905, in create_text_channel
    data = await self._create_channel(name, overwrites, ChannelType.text, category, reason=reason, **options)
  File "/app/.heroku/python/lib/python3.9/site-packages/discord/http.py", line 245, in request
    raise HTTPException(r, data)

Possible solution Would it be possible to add a new configuration to create channels based on snowflakes, i.e. the user IDs, making threads name agnostic?

StephenDaDev commented 3 years ago

This is confirmed and a common problem. A potential solution would be to find a list of these banned words and when one is present use the ID for the channel name instead.

patrickklaeren commented 3 years ago

This is confirmed and a common problem. A potential solution would be to find a list of these banned words and when one is present use the ID for the channel name instead.

I'm not sure you'd be winning a fight against a list which could be constantly changing - I can't even seem to find a published list.

Wouldn't it be easier to allow for configuration and create channel names based on snowflakes?

StephenDaDev commented 3 years ago

In the long run... probably

Trinitek commented 3 years ago

I would suggest inspecting the 400 response for "contains words" and then try again with the snowflake. The response body's content is frozen as part of the Discord API version, no? Would that break unexpectedly? If it does, the worst case is it would just write the error to the log channel.

StephenDaDev commented 3 years ago

Workaround

  1. Manually create a new channel with whichever name you would like.
  2. Set the channel topic to User ID: [the user's ID the thread will work like normal.

*Your modmail logs channel will not display the log URL, however, using the logs command should allow you to view the log of the thread. This is obviously just until a permanent fix has been deployed.