0
votes

I'm trying to implement a reporting system in my discord server, so when Moderators are not online, Users can still send a report to the bot, and the bot will notify the entire Moderator channel.

The code below worked when I tested it as a single user; however, I predicted it wouldn't be that easy. When a User does the !report command and another different user sends a message to the bot, the bot will treat it as one "session."

Please see the screenshots below.

I want the bot to handle all the users in their own "session." If anyone can point me in the right direction, I would immensely appreciate it.

For more clarification the first image is USER A, the 2nd image is USER B, and the final image is final report. As you can see USER A executes the command but if USER B also DMs the BOT it will treat the command as a single session.

enter image description here enter image description here enter image description here

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    if isinstance(message.channel, discord.DMChannel):
        if message.content.startswith("!report"):
            await message.channel.send("Who are we reporting?")
            await message.channel.send("Follow this format: \n"
                                       "User: <enter user ID> (to get a user's id please right click their name and Copy ID) \n"
                                       "Reason: <enter reason> (ex include but not limited too: bullying, harassment, "
                                       "offensive post ")

            msg = await client.wait_for('message')
            await message.channel.send("report received, an admin should be in contact with you soon")
            channel = client.get_channel(REPORT_CHANNEL)
            print(msg)
            await channel.send("report received from user: {}#{}, unique User ID {} ".format(msg.channel.recipient.name, msg.channel.recipient.discriminator, msg.channel.recipient.id))
            await channel.send(msg.content)
1

1 Answers

1
votes

This is because you went with an on_message event approach. The best way to handle sessions like that is with commands.

q_list = [
"Question 1",
"Question 2",
"Question 3"
]

a_list = []

@client.command()
async def report(ctx):
    a_list = []
    submit_channel = client.get_channel(MODERATOR_CHANNEL_ID)
    channel = await ctx.author.create_dm()

    def check(m):
        return m.content is not None and m.channel == channel

    for question in q_list:
        asyncio.sleep(1)
        await channel.send(question)
        msg = await client.wait_for("message", check = check)
        a_list.append(msg.content)

    submit_wait = True
    while submit_wait:
        await channel.send("End of questions type 'submit' to finish")
        msg = await client.wait_for("message", check = check)
        if "submit" in msg.content.lower():
            submit_wait = False
            answers = "\n".join(f"{a}. {b}" for a, b in enumerate(a_list, 1))
            submit_msg = f"Application from {ctx.author} \nThe answers are:\n{answers}"
            await submit_channel.send(submit_msg)