Skip to content

Internal Server Error #4514

@D4rk-S0ul

Description

@D4rk-S0ul

Description

from discord.ext import commands

from Config import ping_role_id


class ThreadSystem(commands.Cog):

    def __init__(self, bot):
        self.client = bot
        self.flag = False

    @commands.Cog.listener()
    async def on_thread_join(self, thread):
        if self.flag:
            self.flag = False
            return
        if not self.flag:
            self.flag = True
        await thread.join()
        ping_role = thread.guild.get_role(ping_role_id)
        members = [m for m in thread.guild.members if ping_role in m.roles]
        member_mentions = []
        for member in members:
            member_mentions.append(member.mention)
        returned_string = ""
        msg = await thread.send("Adding users...")

        for member_mention in member_mentions:
            if len(returned_string + member_mention) > 2000:
                await msg.edit(returned_string)
                returned_string = member_mention
            else:
                returned_string += member_mention + " "
        if msg == "" and len(returned_string) > 0:
            await thread.send(returned_string)
        elif msg != "" and len(returned_string) > 0:
            await msg.edit(returned_string)


def setup(bot):
    bot.add_cog(ThreadSystem(bot))
Ignoring exception in on_thread_join
Traceback (most recent call last):
  File "C:\Users\User\PycharmProjects\RIP_Bot\venv\lib\site-packages\discord\client.py", line 390, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\User\PycharmProjects\RIP_Bot\cogs\ThreadSystem.py", line 30, in on_thread_join
    await msg.edit(returned_string)
  File "C:\Users\User\PycharmProjects\RIP_Bot\venv\lib\site-packages\discord\message.py", line 1429, in edit
    data = await self._state.http.edit_message(
  File "C:\Users\User\PycharmProjects\RIP_Bot\venv\lib\site-packages\discord\http.py", line 381, in request
    raise DiscordServerError(response, data)
discord.errors.DiscordServerError: 500 Internal Server Error (error code: 0): 500: Internal Server Error

This event gets triggert after a thread was created. Since it gets triggered twice per thread (when created and when bot joines) it only reacts to every other event. After that it iterates trough all members on the server and adds those to a list, which have the ping_role. Then it sends a message ("Adding users...") in the thread that was just created, edits it and mentions (without pinging, since it's edited) as many members as the character limit allows and repeats this till everybody in the list was mentioned. It works perfectly fine (but slow) on my test server, but on the bigger server with more than 100 people I (almost) always get the error message above. If this happens, it only sends the "Adding users...", but it doesn't edit it and after around 2min I get the error above.

Steps to Reproduce

Run the code above on a server with 100 members+ and select a role with 100+ members as the ping_role. Create a thread. (Numbers are guessed, may work with less members too)

Expected Behavior

This event gets triggert after a thread was created. Since it gets triggered twice per thread (when created and when bot joines) it only reacts to every other event. After that it iterates trough all members on the server and adds those to a list, which have the ping_role. Then it sends a message ("Adding users...") in the thread that was just created, edits it and mentions (without pinging, since it's edited) as many members as the character limit allows and repeats this till everybody in the list was mentioned.

Current Behavior

It works perfectly fine (but slow) on my test server, but on the bigger server with more than 100 people I (almost) always get the error message above. If this happens, it only sends the "Adding users...", but it doesn't edit it and after around 2min I get the error above.

Screenshots/Videos

No response

Client and System Information

pycharm as IDE, pycord as api wrapper

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions