0
votes

The problem i'm having is the code never getting through "0004" since it gets stuck on wait_for which wants additional positional argument: 'event', which should be the 'message' in bracket right next to it from what I've seen on examples from discord.py site & inside the code itself.

'''

class Test(commands.Cog):
    def __init__(self, spreadsheeter):
        self.spreadsheeter = spreadsheeter

    @commands.command()
    async def apply(self, ctx):
        a_list = []
        submit_channel = spreadsheeter.get_channel(718698172293316608)
        channel = await ctx.author.create_dm()

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

        for question in q_list:
            print("0001")
            sleep(.5)
            print("0002")
            await channel.send(question)
            print("0003")
            msg = await Client.wait_for('message', timeout=60, check=check)
            print("0004")
            a_list.append(msg.content)
            print("0005")

        submit_wait = True
        print("0006")
        while submit_wait:
            print("0007")
            await channel.send("End of questions 'submit' to finish.")
            print("0008")
            msg = await Client.wait_for("message", check=check)
            print("0009")
            if "submit" in msg.content.lower():
                print("0010")
                submit_wait =False
                print("0011")
                answers = "\n".join(f"{a}. {b}" for a, b in enumerate(a_list, 1))
                print("0012")
                submit_msg = f"Apllication from {msg.author} \nThe answers are:\n{answers}"
                print("0013")
                await submit_channel.send(submit_msg)
                print("0014")

Error: Error/Console Log What I've unsuccessfully tried:

discord.client.wait_for('message', check=check)

  • Error: discord.client has no attribute 'wait_for'
  • Same for discord.member, ctx.member, ctx.client

Replacing "message" to 'message' (doesn't change anything)

Moving around the position of 'message'

  • Raises ton of other errors...

Giving the line bracket at start (self, "message", check=check)

  • Error: 'Test' object has no attribute 'loop'

@client.event instead of cog style commands.command

  • Error: Unresolved reference 'client'

Intent of the code: Be called from DM as a command, then start a series of questions from q_list in that DM and then store them into a_list. Then after its done it should submit the a_list into as submit_msg into discord channel.

What it does so far?:
Asks first question from q_list


q_list = [
    "Question one",
    "Question two ha-ha-haaa",
    "Question three ha-ha-haaa"
]

"""

After that it immediately after trying to await answer gives error.

enter image description here

2
Try await self.wait_for("message", check=check)Chrigi
@Chrigi Command raised an exception: AttributeError: 'Test' object has no attribute 'wait_for'otosrEErsoto
Sry it should be await spreadsheeter.wait_for("message", check=check) as spreadsheeter is your clientChrigi
@Chrigi No problem at all. So using the spreadsheeter kinda worked, now it doesn't do any error, but it doesn't do anything now hehe (screen) screen on ctrlv.czotosrEErsoto
I posted an answer down below which should fix that as wellChrigi

2 Answers

0
votes

2 Things at the beginning, you should only make a dm channel if there isn't any yet. ctx.author.chreate_dm() doesn't return a channel, so instead of assigning the dm channel to channel you can check it's in the right channel by using ctx.author.dm_channel

@commands.command()
async def apply(self, ctx):
    a_list = []
    submit_channel = self.spreadsheeter.get_channel(718698172293316608)
    if not ctx.author.dm_channel:
        await ctx.author.create_dm()

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

Instead of Client use spreadsheeter as that is your client

msg = await self.spreadsheeter.wait_for('message', timeout=60, check=check)
0
votes

Figured it out, the thing being is it might work in cogs, but I think it won't or something is just missing... The way i made it to work is to use it in

  • @Client.event (in my case @spreadsheeter.event)
  • Instead of ctx. I used payload.

"""

@spreadsheeter.event
async def on_raw_reaction_add(payload):
    print("Hell-Yeah")
    message_id = payload.message_id
    if message_id == 739153263907176480:
        guild_id = payload.guild_id
        guild = discord.utils.find(lambda g : g.id == guild_id, spreadsheeter.guilds)
        print (payload.emoji.name)

        if payload.emoji.name == "No1":
            role = discord.utils.find(lambda r: r.name == 'RAIDERS', guild.roles)
            print(role)
            if role in payload.member.roles:
                print("You really want to leave?")
            else:
                print("Kick")
                await payload.member.kick()
        elif payload.emoji.name == "Yes1":
            print("Yo, we got a potential raider over here..")
            channel = await payload.member.create_dm()
            await channel.send("This is still Work/Bot is under Development (Not actuall application yet).")
            await channel.send("Whenever you are ready, please start replaying to the questions.")
            print("0000")
            submit_channel = spreadsheeter.get_channel(718698172293316608)

            if not payload.member.dm_channel:
                await payload.member.create_dm()

            channel = payload.member.dm_channel
            print(channel)

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

            for question in q_list:
                print("0001")
                sleep(.5)
                print("0002")
                await channel.send(question)
                print("0003")
                msg = await spreadsheeter.wait_for(event='message', timeout=60, check=check)
                print("0004")
                a_list.append(msg.content)
                print("0005")

            submit_wait = True
            print("0006")
            while submit_wait:
                print("0007")
                await channel.send("End of questions 'submit' to finish.")
                print("0008")
                msg = await spreadsheeter.wait_for("message", timeout=60, check=check)
                print("0009")
                if "submit" in msg.content.lower():
                    print("0010")
                    submit_wait = False
                    print("0011")
                    answers = "\n".join(f"{a}. {b}" for a, b in enumerate(a_list, 1))
                    print("0012")
                    submit_msg = f"Apllication from {msg.author} \nThe answers are:\n{answers}"
                    print("0013")
                    await submit_channel.send(submit_msg)
                    print("0014")

        elif payload.emoji.name == "Need_more_info":
            print("Yo, we got a potential diplomat over here..")
            channel = await payload.member.create_dm()
            await channel.send("This is still Work/Bot is under Development (Not actuall application yet).")
            await channel.send("Whenever you are ready, please start with \n_apply")

"""

It still doesn't have the handling for multiple users, but works fine with one at a time at this moment, which solves the original problem of wait_for not waiting for anything else then timeout to run out.

enter image description here

enter image description here

enter image description here